wip: collision bounds checking for tiles
authorLukas Krickl <lukas@krickl.dev>
Mon, 14 Oct 2024 11:59:09 +0000 (13:59 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 14 Oct 2024 11:59:09 +0000 (13:59 +0200)
src/collision.s
src/wram.s

index 2b9e5d709e798f5316d5bb15cc3f552c39e93ab9..91dcf8e68cddefe39edda28a5880cd0d0c8f7e29 100644 (file)
@@ -32,37 +32,63 @@ collision_player:
 collision_tile_lut:
   .rep cti, ROOM_H, 1, .db cti * ROOM_W 
 
-  ; collision-tile call 
-  ; but using static 
-  ; params in wram:
-  ;   inputs:
-  ;     ct_pty/ct_ptx: collision tile y/x
-  ;     ct_pox/ct_poy: position y/x
-collision_tile_stat:
-  ld a, [ct_pty]
-  ld b, a ; b = pty
-
-  ld a, [ct_ptx]
-  ld c, a ; c = ptx
+  ; checks an entire collision table based on an original point
+  ; and a ptr to a collision point table
+  ; inputs:
+  ;  hl: ptr to y/x position
+  ;  de: collision point table 
+  ; returns:
+  ;   a = 0 -> no collision
+  ;   a = 1 -> collision
+collision_tile_table_check:
+  ld a, [hl+]
+  ld [ct_poy], a ; y buffer 
+  ld a, [hl]
+  ld [ct_pox], a ; x buffer 
 
-  ld a, [ct_poy]
-  ld d, a ; d = poy
+  ld a, [de] ; load loop counter 
+  inc de ; de + 1 = first point y coordinate
+@loop:
+  push af
+  push de
+  push hl
 
+  ld a, [de]
+  ld l, a
   ld a, [ct_poy]
-  ld e, a ; e = pox
+  add a, l ; a = y + collision y offset 
+  inc de
+  
+  ld a, [de]
+  ld h, a
+  ld a, [ct_pox] 
+  add a, h ; a = x + collision x offset 
+  
+  ld d, l
+  ld e, h
+
+  call collision_tile
+
+  pop af
+  pop de
+  pop hl
+
+  dec a ; a--
+  cp a, 0 ; again if not 0
+  jp nz, @loop
+
+  ret
 
-  ; checks a collision ptr 
+  ; checks a point
   ; with a map's meta tile
   ; if the tile has collision flag set 
   ; returns 1 otherwise 0
   ; inputs:
-  ;   b/c: collision point (y/x) 
   ;     d : y pos 
   ;     e : x pos
   ; returns:
   ;   a = 0 -> no collision
   ;   a = 1 -> collision
-  ;   hl += 2
 collision_tile:
   ; y pos / 16 -> tile pos
   sra d ; / 2
index 376b85fb80a9ceb06fab916a3231b0fb02248723..9e7e8de8d3d3c77afbfa8532837a641fac38cb88 100644 (file)
@@ -122,8 +122,6 @@ game_over_timer: .adv 1
 
 game_mode: .adv 1
 
-  ; collision tile params 
-ct_pty: .adv 1
-ct_ptx: .adv 1
+  ; collision tile tmp values  
 ct_poy: .adv 1
 ct_pox: .adv 1