From: Lukas Krickl Date: Mon, 24 Nov 2025 04:52:52 +0000 (+0100) Subject: player: reworked movement to be grid based X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=22ab84cbffb41df4ce8c7bf72b42d6678b942d58;p=gbrg%2F.git player: reworked movement to be grid based --- diff --git a/src/player.s b/src/player.s index 46a11b3..ff68ce3 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/wram.s b/src/wram.s index cc6d33f..4a57ad6 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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