wip: rectangle collision
authorLukas Krickl <lukas@krickl.dev>
Fri, 1 Nov 2024 04:41:52 +0000 (05:41 +0100)
committerLukas Krickl <lukas@krickl.dev>
Fri, 1 Nov 2024 04:41:52 +0000 (05:41 +0100)
src/collision.s

index 350bffdebb0dcebca1ec1674709c2032033e4a1f..33162b7728a2e4a146e28b59f4aad3c565f4a918 100644 (file)
@@ -176,11 +176,33 @@ collision_tile:
   ; check collision between
   ; a point and a provided rectangle 
   ; inputs:
-  ;   d: py y
-  ;   e: pt x
-  ;  bc: ptr to point 0-3 in the rectangle 
+  ;   d: point y
+  ;   e: point x
+  ;   b: rec y
+  ;   c: rec x
+  ;  hl: ptr to point 0-3 in the rectangle 
+  ;      in this order:
+  ;       top left, top right
+  ;       bottom left, bottom right
   ;  returns:
   ;    a = 0 -> no collision
   ;    a = 1 -> collision
 collision_pt_rec:
+  ; check top left
+  ; -> y pos 
+  ld a, [hl+]
+  add a, b ; a = rec y + y offset 
+  cp a, d ; tl < py?
+  jr nc, @no_collision REL
+
+  ; -> x pos
+  ld a, [hl+]
+  add a, c ; a = rec x + x offset 
+  cp a, d ; t1 < px?
+  jr nc, @no_collision REL 
+
+@collision:
+  ld a, 1
+@no_collision:
+  xor a, a
   ret