From 234893be8290ad13d665bc64d6d1d5bd156521f6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 12 Jan 2026 13:21:44 +0100 Subject: [PATCH] player: Added basic movement and rendering --- src/map.s | 11 +++++++++++ src/player.s | 41 +++++++++++++++++++++++++++++++++++++++++ src/update.s | 1 + src/wram.s | 4 ++++ 4 files changed, 57 insertions(+) diff --git a/src/map.s b/src/map.s index 7395094..d632449 100644 --- a/src/map.s +++ b/src/map.s @@ -440,6 +440,17 @@ map_full_draw_row: ; transferts to redraw state map_full_draw: call map_set_visible_range + + ; set map offset + ld a, b + mul8 a + sub a, OBJ_OFF_Y + ld [map_offset_y], a + + ld a, c + mul8 a + sub a, OBJ_OFF_X + ld [map_offset_x], a ; render destination ld hl, render_buffer diff --git a/src/player.s b/src/player.s index 8e707a5..375a7f7 100644 --- a/src/player.s +++ b/src/player.s @@ -60,6 +60,30 @@ player_update: call player_handle_move + ret + + ; draws player +player_draw: + ld a, 1 + call oamalloc + + ; y pos + ld a, 72 + add a, b + ld [hl+], a + + ; x pos + ld a, 88 + ld [hl+], a + + ; tile + ld a, 0xA5 + ld [hl+], a + + ; flags + xor a, a + ld [hl], a + ret @@ -80,21 +104,38 @@ player_handle_move: ld b, DIRLEFT input_just + jr z, @not_left REL + ld a, [player+act_pos_x] + dec a + ld [player+act_pos_x], a + call map_full_draw @not_left: ld b, DIRRIGHT input_just jr z, @not_right REL + ld a, [player+act_pos_x] + inc a + ld [player+act_pos_x], a + call map_full_draw @not_right: ld b, DIRUP input_just jr z, @not_up REL + ld a, [player+act_pos_y] + dec a + ld [player+act_pos_y], a + call map_full_draw @not_up: ld b, DIRDOWN input_just jr z, @not_down REL + ld a, [player+act_pos_y] + inc a + ld [player+act_pos_y], a + call map_full_draw @not_down: ret diff --git a/src/update.s b/src/update.s index 112cb7e..96defe7 100644 --- a/src/update.s +++ b/src/update.s @@ -8,6 +8,7 @@ update_game: ; player should update even in debug mode call player_update + call player_draw ; tick rng every frame call rand diff --git a/src/wram.s b/src/wram.s index ea5b850..0e8da63 100644 --- a/src/wram.s +++ b/src/wram.s @@ -57,6 +57,10 @@ empty_oam: .adv oamsize ; scroll location scroll_y: .adv 1 scroll_x: .adv 1 + ; map offset in pixels + ; use to render actors +map_offset_y: .adv 1 +map_offset_x: .adv 1 ; global animation timer ; increments from 0-30 -- 2.30.2