From: Lukas Krickl Date: Mon, 22 Sep 2025 03:43:32 +0000 (+0200) Subject: rectangle: Added routines to get each point in a rectangle X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=a197a20d6b5b6d9e7b91bf0e9d0cc6c3a55a678d;p=gbrg%2F.git rectangle: Added routines to get each point in a rectangle --- diff --git a/src/rectangle.s b/src/rectangle.s index 3e18848..63c4580 100644 --- a/src/rectangle.s +++ b/src/rectangle.s @@ -80,38 +80,93 @@ rect_find_slot: ld hl, 0 ret - ; tests if any point - ; of r1 is inside r2 + + ; gets top left of a rectangle ; inputs: - ; de: r1 - ; hl: r2 + ; hl: rectangle ; returns: - ; a == 1: inside - ; a == 0: not inside -rect_test: - ld a, [de] - ld b, a + ; de: y/x +rect_tl: + inc hl ; skip mask + ld a, [hl+] + ld d, a ; d = y + ld a, [hl+] + ld e, a ; e = x + ld a, [hl] - ; check if masks have a match - ; otherwise skip - and a, b - cp a, 0 - jp z, @no_collision_mask_match + ld l, a + ld a, d + sub a, l ; y-height + ld d, a ; d = top left y + ret + ; same as rect_tl + ; bototm left +rect_bl: + inc hl ; skip mask + ld a, [hl+] + ld d, a ; d = y + ld a, [hl] + ld e, a ; e = x ret -@no_collision_mask_match: - ld a, 0 + + ; same as rect_tl + ; top right +rect_tr: + inc hl ; skip mask + ld a, [hl+] + ld d, a ; d = y + ld a, [hl+] + ld e, a ; e = x + inc hl ; skip height + + ld a, [hl] + add a, e ; e = x + width + ld e, a + + dec hl ; go back to height + ld a, [hl] + ld l, a + ld a, d + sub a, l ; y-height + ld d, a ; d = top right y ret + ; same as rect_tl + ; bottom right +rect_br: + inc hl ; skip mask + ld a, [hl+] + ld d, a ; d = y + ld a, [hl+] + ld e, a ; e = x + inc hl ; skip height + + ld a, [hl] + add a, e ; e = x + width + ld e, a + ret + ; tests if a point is inside r1 + ; a: mask ; bc: y/x point ; hl: rectangle ; returns: ; a == 1: inside ; a == 0: not inside rect_point_test: - ret + ; check collision mask + ld d, a + ld [hl], a + and a, d + ; exit if mask is no match + jp z, @no_collision_mask_match + + ret +@no_collision_mask_match: + xor a, a + ret ; removes a rectangle ; inputs: