From: Lukas Krickl Date: Sat, 20 Sep 2025 07:10:16 +0000 (+0200) Subject: player: Added basic movement X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=6eec856f7e29684c45aa7e515c9dbe6e9f4333f5;p=gbrg%2F.git player: Added basic movement --- diff --git a/src/player.s b/src/player.s index 4a3147e..31e966c 100644 --- a/src/player.s +++ b/src/player.s @@ -1,3 +1,5 @@ +#define PLAYER_SPEED 1 + ; sets up the player actor player_init: ; initial position @@ -12,9 +14,108 @@ player_init: ; updates the special player actor player_update: + ld b, BTNUP + input_held + jr z, @not_up REL + ld b, PLAYER_SPEED + ld c, 0 + call player_stage_move_n + call player_try_move +@not_up: + + ld b, BTNDOWN + input_held + jr z, @not_down REL + ld b, PLAYER_SPEED + ld c, 0 + call player_stage_move_p + call player_try_move + +@not_down: + + ld b, BTNLEFT + input_held + jr z, @not_left REL + ld b, 0 + ld c, PLAYER_SPEED + call player_stage_move_n + call player_try_move +@not_left: + + ld b, BTNRIGHT + input_held + jr z, @not_right REL + + ld b, 0 + ld c, PLAYER_SPEED + call player_stage_move_p + call player_try_move +@not_right: + ret #define PLAYER_SPRITE_IDLE1 0x8D + + ; stages a move in a positive directon + ; inputs: + ; b/c: y/x movement + ; returns: + ; b/c: new y/x position + ; d: new y hi position +player_stage_move_p: + ld a, [player+act_pos_y] + add a, b + ld b, a + + ld a, [player+act_pos_y_hi] + adc a, 0 + ld [player+act_pos_y_hi], a + ld d, a + + ld a, [player+act_pos_x] + add a, c + ld c, a + + ret + + ; stages a move in a negative directon + ; inputs: + ; b/c: y/x movement + ; returns: + ; b/c: new y/x position + ; d: new y hi position +player_stage_move_n: + ld a, [player+act_pos_y] + sub a, b + ld b, a + + ld a, [player+act_pos_y_hi] + sbc a, 0 + ld [player+act_pos_y_hi], a + ld d, a + + ld a, [player+act_pos_x] + sub a, c + ld c, a + + ret + + ; moves the player + ; performs a collision check + ; moves scroll and performs map loads if needed + ; inputs: + ; b/c: new y/x position + ; d: new y hi position +player_try_move: + ld a, b + ld [player+act_pos_y], a + + ld a, c + ld [player+act_pos_x], a + + ld a, d + ld [player+act_pos_y_hi], a + ret ; draws the special player actor player_draw: