; 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