Prev: B631 Up: Map Next: B691
B647: Check Overlap
Used by the routines at CheckBulletHit and CheckSheriffTouch.
Checks whether two objects overlap. They overlap when the distance between their centres, both across and up the screen, is less than three quarters of the sum of their sizes.
Input
IX The address of the first object
IY The address of the second object
Output
F The carry flag is set if the objects overlap
Check the horizontal distance.
CheckOverlap B647 LD A,(IY+$08) Fetch the horizontal size of the second object.
B64A ADD A,(IX+$08) Add the horizontal size of the first object.
B64D SRL A Halve the sum.
B64F LD C,A Keep half of the summed widths in C.
B650 SRL A Halve it again.
B652 ADD A,C Add the first half to make three quarters of the sum.
B653 LD C,A Keep three quarters of the summed widths in BC.
B654 LD B,$00
B656 LD L,(IX+$01) Fetch the horizontal position of the first object into HL.
B659 LD H,(IX+$02)
B65C LD E,(IY+$01) Fetch the horizontal position of the second object into DE.
B65F LD D,(IY+$02)
B662 AND A Subtract one from the other.
B663 SBC HL,DE
B665 CALL C,NegateHL Make the distance positive.
B668 AND A Subtract the limit.
B669 SBC HL,BC
B66B RET NC Return if the objects are too far apart horizontally.
Check the vertical distance.
B66C LD A,(IY+$09) Fetch the vertical size of the second object.
B66F ADD A,(IX+$09) Add the vertical size of the first object.
B672 SRL A Halve the sum.
B674 LD C,A Keep half of the summed heights in C.
B675 SRL A Halve it again.
B677 ADD A,C Add the first half to make three quarters of the sum.
B678 LD C,A Keep three quarters of the summed heights in BC.
B679 LD B,$00
B67B LD L,(IX+$03) Fetch the vertical position of the first object into HL.
B67E LD H,(IX+$04)
B681 LD E,(IY+$03) Fetch the vertical position of the second object into DE.
B684 LD D,(IY+$04)
B687 AND A Subtract one from the other.
B688 SBC HL,DE
B68A CALL C,NegateHL Make the distance positive.
B68D AND A Subtract the limit.
B68E SBC HL,BC
B690 RET Return.
Prev: B631 Up: Map Next: B691