player: reworked movement to be grid based
authorLukas Krickl <lukas@krickl.dev>
Mon, 24 Nov 2025 04:52:52 +0000 (05:52 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 24 Nov 2025 04:52:52 +0000 (05:52 +0100)
src/player.s
src/wram.s

index 46a11b382eaf05aaf3f3d47ac7e05a469efffcbf..ff68ce323c4c61ea2f76b51de20a832d32771b32 100644 (file)
@@ -13,15 +13,66 @@ player_init:
        ; updates the special player actor
 player_update: 
        call scroll_center_player
+       
+       call player_inputs
+       call player_handle_move
+       ret
+       
+       ; shcedules a player move
+player_inputs:
+       ; no direction inputs if timer is > 0
+       ld a, [player_move_timer]
+       cp a, 0
+       ret nz
+       
+       ld b, BTNUP
+       input_held
+       jr z, @notup REL
+               ld a, DIRUP
+               jp @set
+@notup:
 
-       call move_cursor
+       ld b, BTNDOWN
+       input_held
+       jr z, @notdown REL
+               ld a, DIRDOWN
+               jp @set
+@notdown:      
+
+       ld b, BTNLEFT
+       input_held
+       jr z, @notleft REL
+               ld a, DIRLEFT
+               jp @set
+@notleft:
+
+       ld b, BTNRIGHT
+       input_held
+       jr z, @notright REL
+               ld a, DIRRIGHT
+               jp @set
+@notright:
        ret
+@set:
+       ld [player_direction], a
+       ld a, 16 ; tile size
+       ld [player_move_timer], a
        
+       ret
+
        ; moves the player cursor
        ; does not move out of bounds
-move_cursor:
-       ld b, BTNDOWN 
-       input_held
+       ; based on the last queued input
+player_handle_move:
+       ; remove 1 from timer
+       ld a, [player_move_timer]
+       cp a, 0
+       ret z
+       dec a
+       ld [player_move_timer], a
+
+       ld a, [player_direction]
+       and a, BTNDOWN
        jr z, @not_down REL
                ld a, [player+act_pos_y]
                cp a, 0xF0 ; max value
@@ -30,8 +81,8 @@ move_cursor:
                ld [player+act_pos_y], a
 @not_down:
 
-       ld b, BTNUP
-       input_held
+       ld a, [player_direction]
+       and a, BTNUP
        jr z, @not_up REL
                ld a, [player+act_pos_y]
                cp a, 0 ; min value
@@ -40,8 +91,8 @@ move_cursor:
                ld [player+act_pos_y], a
 @not_up:
 
-       ld b, BTNLEFT
-       input_held
+       ld a, [player_direction]
+       and a, BTNLEFT
        jr z, @not_left REL
                ld a, [player+act_pos_x]
                cp a, 0 ; min value
@@ -50,8 +101,8 @@ move_cursor:
                ld [player+act_pos_x], a
 @not_left:
 
-       ld b, BTNRIGHT
-       input_held
+       ld a, [player_direction]
+       and a, BTNRIGHT
        jr z, @not_right REL
                ld a, [player+act_pos_x]
                cp a, 0xF0 ; max value
index cc6d33f1b50740e86125d38662c50f97c8d73583..4a57ad6cbce4b082bc3d407d9bc2fa312f211537 100644 (file)
@@ -69,6 +69,11 @@ animation_frame: .adv 1
   ; seed must never be 0
 srand: .adv 2
        
+       ; player combtat stats
+player_cb: .adv act_cb_size
+       ; stores the last move direction
+player_direction: .adv 1
+player_move_timer: .adv 1
 
 actors:
 player: .adv act_size