Prev: AE75 Up: Map Next: AEB8
AE78: Searchlight caught
This detects when the hero gets caught in the searchlight.
Used by the routine at nighttime.
Input
HL Pointer to searchlight movement data.
searchlight_caught AE78 LD DE,($81BB) Fetch map_position into DE. E is x, D is y
Detect when the searchlight overlaps the hero.
AE7C LD A,E Compute map_position.x + 12
AE7D ADD A,$0C
AE7F LD B,A Save it in B
AE80 LD A,(HL) Fetch searchlight.x
AE81 ADD A,$05 Compute searchlight.x + 5
AE83 CP B Is (searchlight.x + 5) >= (map_position.x + 12)?
Is the searchlight hotspot left edge beyond the hero's right edge?
AE84 RET NC Return if so - the hero isn't in the hotspot
AE85 ADD A,$05 Compute (searchlight.x + 5) + 5
AE87 DEC B Compute (map_position.x + 12) - 2
AE88 DEC B
AE89 CP B Is (searchlight.x + 10) < (map_position.x + 10)?
Is the searchlight hotspot right edge beyond the hero's left edge?
AE8A RET C Return if so - the hero isn't in the hotspot
AE8B INC HL Advance HL to searchlight.y
AE8C LD A,D Compute map_position.y + 10
AE8D ADD A,$0A
AE8F LD B,A Save it in B
AE90 LD A,(HL) Fetch searchlight.y
AE91 ADD A,$05 Compute searchlight.y + 5
AE93 CP B Is (searchlight.y + 5) >= (map_position.y + 10)?
Is the searchlight hotspot top edge beyond the hero's bottom edge?
AE94 RET NC Return if so - the hero isn't in the hotspot
AE95 ADD A,$07 Compute (searchlight.y + 5) + 7
AE97 LD C,A Save it in C
AE98 LD A,B Compute (map_position.y + 10) - 4
AE99 SUB $04
AE9B CP C Is (map_position.y + 6) >= (searchlight.y + 12)?
Is the searchlight hotspot bottom edge beyond the hero's top edge?
AE9C RET NC Return if so - the hero isn't in the hotspot
The hero is in the hotspot.
Commentary: It seems odd to not do this next test first, since it's cheaper.
AE9D LD A,($81BD) Is searchlight_state set to searchlight_STATE_CAUGHT? ($1F)
AEA0 CP $1F
AEA2 RET Z Return if so
AEA3 LD A,$1F Set searchlight_state to searchlight_STATE_CAUGHT
AEA5 LD ($81BD),A
AEA8 LD D,(HL) Assign searchlight_caught_coord from searchlight.x and .y
AEA9 DEC HL
AEAA LD E,(HL)
AEAB LD ($AE76),DE
AEAF XOR A Make the bell ring perpetually
AEB0 LD ($A130),A
AEB3 LD B,$0A Decrease morale by 10
AEB5 JP decrease_morale Exit via decrease_morale
Prev: AE75 Up: Map Next: AEB8