Prev: 46641 Up: Map Next: 46737
46663: 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 46663 LD A,(IY+8) Fetch the horizontal size of the second object.
46666 ADD A,(IX+8) Add the horizontal size of the first object.
46669 SRL A Halve the sum.
46671 LD C,A Keep half of the summed widths in C.
46672 SRL A Halve it again.
46674 ADD A,C Add the first half to make three quarters of the sum.
46675 LD C,A Keep three quarters of the summed widths in BC.
46676 LD B,0
46678 LD L,(IX+1) Fetch the horizontal position of the first object into HL.
46681 LD H,(IX+2)
46684 LD E,(IY+1) Fetch the horizontal position of the second object into DE.
46687 LD D,(IY+2)
46690 AND A Subtract one from the other.
46691 SBC HL,DE
46693 CALL C,NegateHL Make the distance positive.
46696 AND A Subtract the limit.
46697 SBC HL,BC
46699 RET NC Return if the objects are too far apart horizontally.
Check the vertical distance.
46700 LD A,(IY+9) Fetch the vertical size of the second object.
46703 ADD A,(IX+9) Add the vertical size of the first object.
46706 SRL A Halve the sum.
46708 LD C,A Keep half of the summed heights in C.
46709 SRL A Halve it again.
46711 ADD A,C Add the first half to make three quarters of the sum.
46712 LD C,A Keep three quarters of the summed heights in BC.
46713 LD B,0
46715 LD L,(IX+3) Fetch the vertical position of the first object into HL.
46718 LD H,(IX+4)
46721 LD E,(IY+3) Fetch the vertical position of the second object into DE.
46724 LD D,(IY+4)
46727 AND A Subtract one from the other.
46728 SBC HL,DE
46730 CALL C,NegateHL Make the distance positive.
46733 AND A Subtract the limit.
46734 SBC HL,BC
46736 RET Return.
Prev: 46641 Up: Map Next: 46737