player: targeting now is done by pressing the select button master origin/HEAD origin/master
authorLukas Krickl <lukas@krickl.dev>
Sat, 21 Feb 2026 06:25:07 +0000 (07:25 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 21 Feb 2026 06:25:07 +0000 (07:25 +0100)
src/player.s
src/wram.s

index 6b7517f5eeab1b3b6b3c033bdd1a5f13e7b48c66..1305d32fbb884969f9df8d6609039f775cd0aac0 100644 (file)
@@ -192,6 +192,37 @@ player_do_action_b:
        ld l, a
        jp action_exec
        
        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
        ; moves the player 
        ; does not move out of bounds
        ; based on the last queued input
@@ -208,10 +239,13 @@ player_handle_move:
                call player_do_action_b
 @not_action_b:
 
                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
        ld b, DIRLEFT
        input_held
        jr z, @not_left REL
-               _player_set_target 0, -1
 
                ld a, [player+act_pos_x]
                dec a
 
                ld a, [player+act_pos_x]
                dec a
@@ -232,7 +266,6 @@ player_handle_move:
        ld b, DIRRIGHT
        input_held
        jr z, @not_right REL
        ld b, DIRRIGHT
        input_held
        jr z, @not_right REL
-               _player_set_target 0, 1
 
                ld a, [player+act_pos_x]
                inc a
 
                ld a, [player+act_pos_x]
                inc a
@@ -252,7 +285,6 @@ player_handle_move:
        ld b, DIRUP
        input_held
        jr z, @not_up REL
        ld b, DIRUP
        input_held
        jr z, @not_up REL
-               _player_set_target -1, 0
 
                ld a, [player+act_pos_y]
                dec a
 
                ld a, [player+act_pos_y]
                dec a
@@ -274,7 +306,6 @@ player_handle_move:
        ld b, DIRDOWN
        input_held
        jr z, @not_down REL
        ld b, DIRDOWN
        input_held
        jr z, @not_down REL
-               _player_set_target 1, 0
 
                ld a, [player+act_pos_y]
                inc a
 
                ld a, [player+act_pos_y]
                inc a
index 27ed876b95f99eb1da064296ef3b6ea93171609d..bdf805dad09f1d83e9872c4c259dab17f5dfc8ab 100644 (file)
@@ -101,6 +101,8 @@ player_viewradius: .adv 1
 player_target_y: .adv 1
 player_target_x: .adv 1
 
 player_target_y: .adv 1
 player_target_x: .adv 1
 
+player_target_index: .adv 1
+
        ; ptrs to actions on a or b button
 player_action_a: .adv 2
 player_action_b: .adv 2
        ; ptrs to actions on a or b button
 player_action_a: .adv 2
 player_action_b: .adv 2