Fix that CheckObjectCoveredByTextbox doesn't account for the background scroll (SCX/SCY) (#8)

This commit is contained in:
xCrystal 2023-10-31 16:02:37 +01:00
parent dadbc72764
commit 85f9c258b5
2 changed files with 29 additions and 5 deletions

View File

@ -2406,18 +2406,14 @@ CheckObjectCoveredByTextbox:
ldh a, [hCurSpriteYCoord]
add e
dec a
cp SCREEN_HEIGHT
jr nc, .ok9
ld b, a
.next
ldh a, [hCurSpriteXCoord]
add d
dec a
cp SCREEN_WIDTH
jr nc, .ok8
ld c, a
push bc
call Coord2Tile
call ScrollAwareCoord2Tile
pop bc
; NPCs disappear if standing on tiles FIRST_REGULAR_TEXT_CHAR or above,
; since those IDs are for text characters and textbox frames.

View File

@ -257,6 +257,34 @@ ClearWholeMenuBox::
call ClearBox
ret
ScrollAwareCoord2Tile::
; Return the address of wTilemap(c, b) in hl relative to the background scroll in hSCX and hSCY.
; c = c - [hSCX] / 8
ld a, [hSCX]
srl a
srl a
srl a
ld l, a
ld a, c
sub l
jr nc, .ok1
add BG_MAP_WIDTH
.ok1
ld c, a
; b = b - [hSCY] / 8
ld a, [hSCY]
srl a
srl a
srl a
ld l, a
ld a, b
sub l
jr nc, .ok2
add BG_MAP_HEIGHT
.ok2
ld b, a
jr Coord2Tile
MenuBoxCoord2Tile::
ld a, [wMenuBorderLeftCoord]
ld c, a