player: Added cursor movement
authorLukas Krickl <lukas@krickl.dev>
Sat, 1 Nov 2025 06:49:24 +0000 (07:49 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 1 Nov 2025 06:49:24 +0000 (07:49 +0100)
fixed cursor rendering

src/player.s

index 9a98f0efbc61897529236ee6926b144889dd0aa6..a1b2713193034cf0db6179f4a82c3532ccb5080b 100644 (file)
@@ -13,6 +13,44 @@ player_init:
        ; updates the special player actor
 player_update: 
        call scroll_center_player
+
+       call move_cursor
+       ret
+       
+       ; moves the player cursor
+       ; does not move out of bounds
+move_cursor:
+       ld b, BTNDOWN 
+       input_held
+       jr z, @not_down REL
+               ld a, [player+act_pos_y]
+               inc a
+               ld [player+act_pos_y], a
+@not_down:
+
+       ld b, BTNUP
+       input_held
+       jr z, @not_up REL
+               ld a, [player+act_pos_y]
+               dec a
+               ld [player+act_pos_y], a
+@not_up:
+
+       ld b, BTNLEFT
+       input_held
+       jr z, @not_left REL
+               ld a, [player+act_pos_x]
+               dec a
+               ld [player+act_pos_x], a
+@not_left:
+
+       ld b, BTNRIGHT
+       input_held
+       jr z, @not_right REL
+               ld a, [player+act_pos_x]
+               inc a
+               ld [player+act_pos_x], a
+@not_right:    
        ret
        
        ; draws player at current location
@@ -28,7 +66,7 @@ player_draw:
 
        ld a, [player+act_pos_y]
        add a, OBJ_OFF_Y
-       sub a, b
+       sub a, b ; - scroll y
        ; store y for second obj
        ld [tmp_y], a
 
@@ -38,10 +76,10 @@ player_draw:
        ; calculate x pos
        ld a, [scroll_x]
        ld b, a
-       sub a, b
 
        ld a, [player+act_pos_x]
        add a, OBJ_OFF_X
+       sub a, b ; - scroll x
        ; store x for second obj
        ld [tmp_x], a