Adding collision tile mask
authorLukas Krickl <lukas@krickl.dev>
Sat, 19 Oct 2024 03:13:20 +0000 (05:13 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 19 Oct 2024 03:13:20 +0000 (05:13 +0200)
src/collision.s
src/player.s
src/wram.s

index 93192b894c6cfe6bc3575a0caac579327131b786..c602dc5078f10c2df3917148a92f4aea6139f114 100644 (file)
@@ -37,6 +37,7 @@ collision_tile_lut:
   ; inputs:
   ;  hl: ptr to y/x position
   ;  de: collision point table 
+  ; ct_mask: bit mask for flag to check
   ; returns:
   ;   a = 0 -> no collision
   ;   a = 1 -> collision
@@ -96,6 +97,7 @@ collision_tile_table_check:
   ; inputs:
   ;     d : y pos 
   ;     e : x pos
+  ; ct_mask: bit mask for flag to check (tile & mask)
   ; returns:
   ;   a = 0 -> no collision
   ;   a = 1 -> collision
@@ -126,4 +128,13 @@ collision_tile:
   ld a, [hl] ; a = map flags row offset 
   add a, e ; row + x = position of tile in map 
 
+  ld d, 0
+  ld e, a ; de = tile offset 
+  ld hl, curr_room_flags ; hl = flags for currently loaded room 
+  add hl, de ; hl + de 
+  ld a, [hl] ; load flags
+  ld d, a
+  ld a, [ct_mask]
+  and a, d
+
   ret
index 30eb25f705dac726b5deea74db7ccc659741f31b..16205c9791c5fc2e284a15913c853c595c05e112 100644 (file)
@@ -49,7 +49,11 @@ player_init:
   ; inputs:
   ;   hl: pointer to player memory
 player_update:
-  ; update 
+  ; update
+
+  ; set collision mask
+  ld a, RF_WALL 
+  ld [ct_mask], a
 
   ; d: player_y
   ; e: player_x
index 9e7e8de8d3d3c77afbfa8532837a641fac38cb88..755b57f0e5402e3b046fb79e065180a02c7909d4 100644 (file)
@@ -125,3 +125,4 @@ game_mode: .adv 1
   ; collision tile tmp values  
 ct_poy: .adv 1
 ct_pox: .adv 1
+ct_mask: .adv 1