player: target is now a vector instead of an absolute position
authorLukas Krickl <lukas@krickl.dev>
Thu, 22 Jan 2026 04:07:21 +0000 (05:07 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 22 Jan 2026 04:07:21 +0000 (05:07 +0100)
src/player.s
src/update.s
src/wram.s

index 69f7a84d3dd8763b34cde3796b84120e3239ea69..21fa61e5a2e6fa91077aa1dde2d831fbdf1bf20a 100644 (file)
@@ -6,12 +6,10 @@
        ;               $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
 
@@ -119,12 +117,18 @@ player_draw:
 
        ; 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
 
@@ -157,6 +161,8 @@ player_handle_move:
        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
@@ -171,13 +177,13 @@ player_handle_move:
                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
@@ -191,13 +197,13 @@ player_handle_move:
                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
@@ -208,16 +214,18 @@ player_handle_move:
                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
@@ -227,12 +235,10 @@ player_handle_move:
                
                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
        
index c66cdbc3ecccc89a4ee5fc9eb70c7c6447da51b1..a13786508fa54c199c76e83cf6038e5c075af933 100644 (file)
@@ -52,7 +52,7 @@ tick:
 
 update_render:
        call disableinterrupts
-
+       
   ; enable objects
   ld a, [RLCD]
   or a, LCDCF_OBJON
index 7f9990485c28726b5eca0c36cad7ccf01ef3dc1e..4ef3fa4ffb124d810d30ad0c15bb22f0f0224e8b 100644 (file)
@@ -93,7 +93,7 @@ player_eq: .adv eq_size
        ; 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