; $1: inc/dec for y position (e.g. 0, 1, -1)
; $2: inc/dec for x position (e.g. 0, 1, -1)
#macro _player_set_target
- ld a, [player+act_pos_y]
- add a, $1 & 0xFF
+ ld a, $1 & 0xFF
ld [player_target_y], a
- ld a, [player+act_pos_x]
- add a, $2 & 0xFF
+ ld a, $2 & 0xFF
ld [player_target_x], a
#endmacro
; draw target position
; y pos
+ ld a, [player+act_pos_y]
+ ld b, a
ld a, [player_target_y]
+ add a, b
_act_pos_offset_y
ld [hl+], a
; x pos
+ ld a, [player+act_pos_x]
+ ld b, a
ld a, [player_target_x]
+ add a, b
_act_pos_offset_x
ld [hl+], a
ld b, DIRLEFT
input_held
jr z, @not_left REL
+ _player_set_target 0, -1
+
ld a, [player+act_pos_x]
dec a
ld c, a
cp a, 0
call z, player_moved
call player_collided
-
- _player_set_target 0, -1
@not_left:
ld b, DIRRIGHT
input_held
jr z, @not_right REL
+ _player_set_target 0, 1
+
ld a, [player+act_pos_x]
inc a
ld c, a
cp a, 0
call z, player_moved
call player_collided
-
- _player_set_target 0, 1
@not_right:
ld b, DIRUP
input_held
jr z, @not_up REL
+ _player_set_target -1, 0
+
ld a, [player+act_pos_y]
dec a
ld b, a
ld de, player
call act_move_to
+
cp a, 0
call z, player_moved
call player_collided
- _player_set_target -1, 0
@not_up:
ld b, DIRDOWN
input_held
jr z, @not_down REL
+ _player_set_target 1, 0
+
ld a, [player+act_pos_y]
inc a
ld b, a
ld de, player
call act_move_to
-
+
cp a, 0
call z, player_moved
call player_collided
-
- _player_set_target 1, 0
@not_down:
ret
; player view distance radius
player_viewradius: .adv 1
- ; player target position
+ ; player target vector
; used for attacks and casts
player_target_y: .adv 1
player_target_x: .adv 1