Added basic left/right collision
authorLukas Krickl <lukas@krickl.dev>
Sat, 19 Oct 2024 14:54:33 +0000 (16:54 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 19 Oct 2024 14:54:33 +0000 (16:54 +0200)
src/collision.s
src/player.s

index 66f81723cfba4167a4b5dcbf124ae20698ae21d4..8efc484f67e2952721c58bd9cecbdd7b6b47c915 100644 (file)
 
 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 
index 1356ed511dfbbd1256b47662da10ac05076174e9..b66d176fc445fa53866e74c2fa29da3ef5ee7556 100644 (file)
   ; 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