From bf2e655fc2347eb0c113d59042adc004ceadaeb7 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 19 Oct 2024 07:36:32 +0200 Subject: [PATCH] Moved player collision call to a macro --- src/collision.s | 8 ++++++++ src/map.s | 8 ++++---- src/player.s | 47 +++++++++++++++++++++++++++++++++-------------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/collision.s b/src/collision.s index 63406bb..66f8172 100644 --- a/src/collision.s +++ b/src/collision.s @@ -29,6 +29,14 @@ collision_player_top: ; center right col_point 0, 10 +collision_player_bot: + col_head 2 + ; center left + col_point 12, 0 + ; center right + col_point 12, 10 + + collision_tile_lut: .rep cti, ROOM_H, 1, .db cti * ROOM_W diff --git a/src/map.s b/src/map.s index 5713f4b..a50200a 100644 --- a/src/map.s +++ b/src/map.s @@ -158,10 +158,10 @@ base_room: ; tile flags for the room base_room_flags: .db RF_WALL, RF_WALL, RF_WALL, RF_WALL, 0, 0, RF_WALL, RF_WALL, RF_WALL, RF_WALL +.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL +.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL +.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL .db RF_WALL, RF_WALL, RF_WALL, RF_WALL, 0, 0, RF_WALL, RF_WALL, RF_WALL, RF_WALL diff --git a/src/player.s b/src/player.s index 16205c9..1356ed5 100644 --- a/src/player.s +++ b/src/player.s @@ -42,6 +42,28 @@ player_init: ret + ; performs a simple collision check + ; inputs: + ; $1: collision table + ; hl: y/x coordinate + ; returns: + ; z/nz -> collision hit or not +#macro player_collision_check + ; check collision + ; 1) save registers + push hl + push de + + ; 2) hl = player_y already + ; 3) load correct collision points + ld de, $1 + call collision_tile_table_check + pop de + pop hl + + cp a, 0 +#endmacro + ; update the player ; players do not behave like regular actors ; and are not allocate to the regular @@ -68,6 +90,15 @@ player_update: ld a, [hl] inc a ld [hl], a + + + player_collision_check collision_player_bot + jr z, @no_collision_up REL + ld a, [hl] + dec a + ld [hl], a +@no_collision_down: + @notdown: input_held BTNUP @@ -77,20 +108,8 @@ player_update: ld a, [hl] dec a ld [hl], a - - ; check collision - ; 1) save registers - push hl - push de - - ; 2) hl = player_y already - ; 3) load correct collision points - ld de, collision_player_top - call collision_tile_table_check - pop de - pop hl - - cp a, 0 + + player_collision_check collision_player_top jr z, @no_collision_up REL ld a, [hl] inc a -- 2.30.2