Prev: A5A7 Up: Map Next: A625
A5EA: Compare Positions
Used by the routines at CheckEnemyOverlap and CheckShotHit.
Compares the position of an entity with the position of another one, in both directions.
Input
IY Entity to compare with
DE X position
HL Y position
B Maximum difference in the Y direction
C Maximum difference in the X direction
Output
F The carry flag is set if both differences are small enough
ComparePositions A5EA PUSH HL Save the Y position...
A5EB PUSH DE ...and the X position.
A5EC LD E,(IY+$03) Fetch the Y position of the other entity.
A5EF LD D,(IY+$04)
A5F2 AND A Subtract it from the Y position, and jump if the result is positive.
A5F3 SBC HL,DE
A5F5 JR NC,ComparePositions_TestY
A5F7 EX DE,HL Otherwise negate it.
A5F8 AND A
A5F9 LD HL,$0000
A5FC SBC HL,DE
ComparePositions_TestY A5FE LD A,H Jump if the difference is more than the size of the world.
A5FF AND $3F
A601 JR NZ,ComparePositions_Done
A603 LD A,L Jump if the difference is not less than the maximum.
A604 CP B
A605 JR NC,ComparePositions_Done
A607 POP HL Restore the X position into HL and save it again.
A608 PUSH HL
A609 LD E,(IY+$01) Fetch the X position of the other entity.
A60C LD D,(IY+$02)
A60F AND A Subtract it from the X position, and jump if the result is positive.
A610 SBC HL,DE
A612 JR NC,ComparePositions_TestX
A614 EX DE,HL Otherwise negate it.
A615 AND A
A616 LD HL,$0000
A619 SBC HL,DE
ComparePositions_TestX A61B LD A,H Jump if the difference is more than the size of the world.
A61C AND $3F
A61E JR NZ,ComparePositions_Done
A620 LD A,L Compare the difference with the maximum, which sets the carry flag if it is less.
A621 CP C
ComparePositions_Done A622 POP DE Restore the X position...
A623 POP HL ...and the Y position.
A624 RET Return.
Prev: A5A7 Up: Map Next: A625