; a == 1: inside
; a == 0: not inside
rect_point_test:
- ; TODO: remove store hl
- ld a, h
- ld [h2], a
- ld a, l
- ld [l2], a
-
inc hl ; skip mask
; bottom left
; load bottom left point
ld a, [hl+]
+ ; TODO: remove use of d2
+ ld [d2], a ; save y in d2
ld d, a ; d = y
- ld a, [hl]
+ ld a, [hl+]
ld e, a ; e = x
ld a, b ; compare y
cp a, e
jr c, @no_collision REL
- ; TODO: remove restore hl
- ld a, [h2]
- ld h, a
- ld a, [l2]
- ld l, a
; top left
+
+ ; get top left y point
+ ld a, [hl+]
push hl
- call rect_tl
+ ld l, a ; TODO: remove use of l to avoid push
+ ld a, d
+ sub a, l ; y-height
+ capunderflow
+ ld d, a ; d = top left y
pop hl
ld a, b ; compare y points
; top right
- push hl
- call rect_tr
- pop hl
+
+ ; get top right x
+ ld a, [hl]
+ add a, e ; e = x + width
+ capoverflow
+ ld e, a
ld a, b ; compare y
cp a, d
; bottom right
- push hl
- call rect_br
- pop hl
+
+ ; remove height from y
+ ; to get bottom right point
+ ld a, [d2] ; d2 = original y point
+ ld d, a
ld a, b ; compare y
- jr c, @no_collision REL
+ cp a, d
+ jr nc, @no_collision REL
ld a, c ; compare x
cp a, e
jr nc, @no_collision REL