ld l, a
jp action_exec
+ ; y/x coordinates for target update
+_player_update_target_coords:
+ .db 0, -1
+ .db -1, 0
+ .db 0, 1
+ .db 1, 0
+
+ ; rotates the current target
+player_update_target:
+ ld a, [player_target_index]
+ inc a
+ and a, 3 ; there are only 4 directions
+ ld [player_target_index], a
+
+ add a, a ; *2 to get 2 byte offset
+
+ ld hl, _player_update_target_coords
+ ld d, 0
+ ld e, a
+ add hl, de
+
+ ; y pos
+ ld a, [hl+]
+ ld [player_target_y], a
+ ld a, [hl]
+
+ ; x pos
+ ld [player_target_x], a
+ ret
+
+
; moves the player
; does not move out of bounds
; based on the last queued input
call player_do_action_b
@not_action_b:
+ ld b, BTNSELECT
+ input_just
+ call nz, player_update_target
+
ld b, DIRLEFT
input_held
jr z, @not_left REL
- _player_set_target 0, -1
ld a, [player+act_pos_x]
dec a
ld b, DIRRIGHT
input_held
jr z, @not_right REL
- _player_set_target 0, 1
ld a, [player+act_pos_x]
inc a
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, DIRDOWN
input_held
jr z, @not_down REL
- _player_set_target 1, 0
ld a, [player+act_pos_y]
inc a