From 7e48810ad0161dcf1ef5ec26c232accc18ff65b0 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 19 Oct 2024 16:54:33 +0200 Subject: [PATCH] Added basic left/right collision --- src/collision.s | 14 ++++++++++---- src/player.s | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/collision.s b/src/collision.s index 66f8172..8efc484 100644 --- a/src/collision.s +++ b/src/collision.s @@ -24,18 +24,24 @@ collision_player_top: col_head 2 - ; center left col_point 0, 0 - ; 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_player_right: + col_head 2 + col_point 0, 10 + col_point 12, 10 + +collision_player_left: + col_head 2 + col_point 0, 0 + col_point 12, 0 + collision_tile_lut: .rep cti, ROOM_H, 1, .db cti * ROOM_W diff --git a/src/player.s b/src/player.s index 1356ed5..b66d176 100644 --- a/src/player.s +++ b/src/player.s @@ -12,11 +12,13 @@ ; inputs: ; hl: pointer to player memory player_init: - xor a, a + ld a, 64 ; y ld [hl+], a ; x ld [hl+], a + + xor a, a ; flags ld [hl+], a @@ -131,6 +133,17 @@ player_update: ld a, [hl] dec a ld [hl], a + + + dec hl ; hl = player_y + player_collision_check collision_player_left + inc hl ; hl = player_x + jr z, @no_collision_left REL + ld a, [hl] + inc a + ld [hl], a +@no_collision_left: + @notleft: input_held BTNRIGHT @@ -140,6 +153,17 @@ player_update: ld a, [hl] inc a ld [hl], a + + + dec hl ; hl = player_y + player_collision_check collision_player_right + inc hl ; hl = player_x + jr z, @no_collision_right REL + ld a, [hl] + dec a + ld [hl], a +@no_collision_right: + @notright: input_just BTNA -- 2.30.2