From: Lukas Krickl Date: Fri, 1 Nov 2024 04:41:52 +0000 (+0100) Subject: wip: rectangle collision X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=ed59ae05e93a8593f78ca136bd54df9baf153a4c;p=gbrg%2F.git wip: rectangle collision --- diff --git a/src/collision.s b/src/collision.s index 350bffd..33162b7 100644 --- a/src/collision.s +++ b/src/collision.s @@ -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