Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boulders block trainer sight #969

Draft
wants to merge 1 commit into
base: 9bit
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 207 additions & 0 deletions home/trainers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,220 @@ FacingPlayerDistance::
call GetSpriteDirection
cp e
jr nz, .NotFacing

push de
ld hl, OBJECT_MAP_X ; x
add hl, bc
ld d, [hl]

ld hl, OBJECT_MAP_Y ; y
add hl, bc
ld e, [hl]

cp OW_LEFT
jr z, .check_boulder_left
cp OW_RIGHT
jr z, .check_boulder_right
cp OW_UP
jr z, .check_boulder_up
jmp .check_boulder_down

.is_facing
scf
ret

.NotFacing:
and a
ret

.check_boulder_left
; trainer x = d, y = e
push bc
ld bc, wObject1Struct
ld hl, OBJECT_MAP_X
add hl, bc
.check_boulder_left_loop
; boulder would need to be at the left of the trainer
ld a, [hl]
cp d
jr nc, .next_left_check
; boulder would need to be to the right of the player
ld hl, wPlayerMapX
cp [hl]
jr c, .next_left_check
; boulder would need to be at the same y as the trainer
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .next_left_check
; check for boulder sprite
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
cp SPRITE_BOULDER_ROCK_FOSSIL
jr nz, .next_left_check
Comment on lines +283 to +284
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we do this at all, it should be a general-purpose "no trainer sight if there's any NPC in the way" check. (And even then, I'd prefer to redesign maps so the circumstance can't occur, if possible.)

; found a boulder
pop bc
pop de
jr .NotFacing

.next_left_check
ld hl, OBJECT_LENGTH + OBJECT_MAP_X
add hl, bc
ld b, h
ld c, l
ld a, b
cp HIGH(wObjectStructsEnd)
jr nz, .check_boulder_left_loop
ld a, c
cp LOW(wObjectStructsEnd)
jr nz, .check_boulder_left_loop
pop bc
pop de
jr .is_facing

.check_boulder_right
; trainer x = d, y = e
push bc
ld bc, wObject1Struct
ld hl, OBJECT_MAP_X
add hl, bc
.check_boulder_right_loop
; boulder would need to be at the right of the trainer
ld a, [hl]
cp d
jr c, .next_right_check
; boulder would need to be to the left of the player
ld hl, wPlayerMapX
cp [hl]
jr nc, .next_right_check
; boulder would need to be at the same y as the trainer
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .next_right_check
; check for boulder sprite
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
cp SPRITE_BOULDER_ROCK_FOSSIL
jr nz, .next_right_check
; found a boulder
pop bc
pop de
jr .NotFacing

.next_right_check
ld hl, OBJECT_LENGTH + OBJECT_MAP_X
add hl, bc
ld b, h
ld c, l
ld a, b
cp HIGH(wObjectStructsEnd)
jr nz, .check_boulder_right_loop
ld a, c
cp LOW(wObjectStructsEnd)
jr nz, .check_boulder_right_loop
pop bc
pop de
jr .is_facing

.check_boulder_up
; trainer x = d, y = e
push bc
ld bc, wObject1Struct
ld hl, OBJECT_MAP_Y
add hl, bc
.check_boulder_up_loop
; boulder would need to be above the trainer
ld a, [hl]
cp e
jr nc, .next_up_check
; boulder would need to be below the player
ld hl, wPlayerMapY
cp [hl]
jr c, .next_up_check
; boulder would need to be at the same x as the trainer
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .next_up_check
; check for boulder sprite
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
cp SPRITE_BOULDER_ROCK_FOSSIL
jr nz, .next_up_check
; found a boulder
pop bc
pop de
jmp .NotFacing

.next_up_check
ld hl, OBJECT_LENGTH + OBJECT_MAP_Y
add hl, bc
ld b, h
ld c, l
ld a, b
cp HIGH(wObjectStructsEnd)
jr nz, .check_boulder_up_loop
ld a, c
cp LOW(wObjectStructsEnd)
jr nz, .check_boulder_up_loop
pop bc
pop de
jmp .is_facing

.check_boulder_down
; trainer x = d, y = e
push bc
ld bc, wObject1Struct
ld hl, OBJECT_MAP_Y
add hl, bc
.check_boulder_down_loop
; boulder would need to be below the trainer
ld a, [hl]
cp e
jr c, .next_down_check
; boulder would need to be above the player
ld hl, wPlayerMapY
cp [hl]
jr nc, .next_down_check
; boulder would need to be at the same x as the trainer
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .next_down_check
; check for boulder sprite
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
cp SPRITE_BOULDER_ROCK_FOSSIL
jr nz, .next_down_check
; found a boulder
pop bc
pop de
jmp .NotFacing

.next_down_check
ld hl, OBJECT_LENGTH + OBJECT_MAP_Y
add hl, bc
ld b, h
ld c, l
ld a, b
cp HIGH(wObjectStructsEnd)
jr nz, .check_boulder_down_loop
ld a, c
cp LOW(wObjectStructsEnd)
jr nz, .check_boulder_down_loop
pop bc
pop de
jmp .is_facing

PrintWinLossText::
ld a, [wBattleResult]
ld hl, wWinTextPointer
Expand Down