Moved player collision call to a macro
authorLukas Krickl <lukas@krickl.dev>
Sat, 19 Oct 2024 05:36:32 +0000 (07:36 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 19 Oct 2024 05:36:32 +0000 (07:36 +0200)
src/collision.s
src/map.s
src/player.s

index 63406bb43c083feaf4132923d18829a7a373ed41..66f81723cfba4167a4b5dcbf124ae20698ae21d4 100644 (file)
@@ -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 
 
index 5713f4b0e608558dcd7056d73372c37b2cbebf61..a50200a4ed07b0edcd2eb359f9f04a58845fdf91 100644 (file)
--- 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 
index 16205c9791c5fc2e284a15913c853c595c05e112..1356ed511dfbbd1256b47662da10ac05076174e9 100644 (file)
@@ -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