From f97f623ec3df667b8886922316ad962be287e3da Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 8 Dec 2025 09:49:16 +0100 Subject: [PATCH] player: wip jumping --- maps/spawn.inc | 6 +++--- src/actor.s | 40 +++++++++++++++++++++++++++++----------- src/player.s | 24 +++++++++++++++++++++++- src/wram.s | 7 +++++++ 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/maps/spawn.inc b/maps/spawn.inc index da0c226..37ff478 100644 --- a/maps/spawn.inc +++ b/maps/spawn.inc @@ -1,8 +1,8 @@ ; this map was generated by tmx2map.py -.db 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 -.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 -.db 0x0, 0x1, 0x2, 0x5, 0x3, 0x4, 0x0, 0x0 +.db 0x1, 0x2, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5 +.db 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5 +.db 0x5, 0x1, 0x2, 0x5, 0x3, 0x4, 0x0, 0x0 .db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 .db 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x4, 0x5 .db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 diff --git a/src/actor.s b/src/actor.s index 24b35ad..3354a64 100644 --- a/src/actor.s +++ b/src/actor.s @@ -61,34 +61,41 @@ act_rollback_pos_y: ; col_prev_pos: set to previous positions ; if collision occures rolls back to ; previous position + ; retuns: + ; col_tile_collided_with: directions collided with act_test_tile_collision: + xor a, a + ld [col_tile_collided_with], a + + push af ld a, [col_direction] and a, DIRUP call nz, _act_test_tile_up_collision + pop bc + or a, b + push af ld a, [col_direction] and a, DIRDOWN call nz, _act_test_tile_down_collision + pop bc + or a, b + push af ld a, [col_direction] and a, DIRLEFT call nz, _act_test_tile_left_collision + pop bc + or a, b + push af ld a, [col_direction] and a, DIRRIGHT call nz, _act_test_tile_right_collision + pop bc + or a, b - - ld hl, act_pos_y - add hl, de - - ; b/c = y/x - call map_get_tile - - ld de, t_flags - add hl, de - ld a, [hl] - and a, TF_WALL + ld [col_tile_collided_with], a ret @@ -132,6 +139,9 @@ act_test_tile_collision: ; test direction routines: ; preserve: de + ; retunrs: + ; a: collided direction bit + ; a: 0 no collision _act_test_tile_left_collision: push de @@ -142,10 +152,12 @@ _act_test_tile_left_collision: _act_tile_col_check col_point_bl, (-1 & 0xFF), 0, @collision pop de + xor a, a ret @collision: pop de call act_rollback_pos_x + ld a, DIRLEFT ret _act_test_tile_right_collision: @@ -158,10 +170,12 @@ _act_test_tile_right_collision: _act_tile_col_check col_point_br, (-1 & 0xFF), 0, @collision pop de + xor a, a ret @collision: pop de call act_rollback_pos_x + ld a, DIRRIGHT ret _act_test_tile_up_collision: @@ -174,10 +188,12 @@ _act_test_tile_up_collision: _act_tile_col_check col_point_tr, 0, (-1 & 0xFF), @collision pop de + xor a, a ret @collision: pop de call act_rollback_pos_y + ld a, DIRUP ret _act_test_tile_down_collision: @@ -190,10 +206,12 @@ _act_test_tile_down_collision: _act_tile_col_check col_point_br, 0, (-1 & 0xFF), @collision pop de + xor a, a ret @collision: pop de call act_rollback_pos_y + ld a, DIRDOWN ret ; update routines for each actor diff --git a/src/player.s b/src/player.s index 0dc8702..645418f 100644 --- a/src/player.s +++ b/src/player.s @@ -79,6 +79,24 @@ player_update: pop de call act_test_tile_collision + ld a, [col_tile_collided_with] + and a, DIRUP + jr z, @not_up_collision REL + ld a, 1 + ld [player_jump_peak], a +@not_up_collision: + + ld a, [col_tile_collided_with] + and a, DIRDOWN + jr z, @not_down_collision REL + ; wait for input button to be cleared before grounding player + ld a, [curr_inputs] + and a, BTNA + jr nz, @not_down_collision REL + + xor a, a + ld [player_jump_peak], a +@not_down_collision: ret ; moves the player @@ -102,9 +120,13 @@ player_handle_move: ld [col_direction], a @not_down: - ld b, BTNUP + ld b, BTNA input_held jr z, @not_up REL + ld a, [player_jump_peak] + cp a, 0 + jr nz, @not_up REL + ld a, [player+act_pos_y] cp a, 0 ; min value jr z, @not_up REL diff --git a/src/wram.s b/src/wram.s index 9ab5bb9..ededf33 100644 --- a/src/wram.s +++ b/src/wram.s @@ -72,6 +72,11 @@ srand: .adv 2 ; stores the last move direction player_direction: .adv 1 + ; how many frames can the player jump? +player_jump_timer: .adv 1 + ; flag to indicate player jump has peaked +player_jump_peak: .adv 1 + actors: player: .adv act_size map_actors: .adv act_size * ACT_MAX @@ -103,6 +108,8 @@ col_point_ct: .adv 2 ; in. this is required so that the collision code ; can handle pushbacks in case of wall collision col_direction: .adv 2 + ; holds tile collision direction result +col_tile_collided_with: .adv 1 ; y/x previous position col_prev_pos: .adv 2 -- 2.30.2