Prev: B81C Up: Map Next: B8AD
B873: Test Object Overlap
Used by the routine at SlideActorPastObjects.
Tests whether an actor at a position would overlap with any object in a list. The list is made up of four byte entries. The first two bytes are the address of the graphic of the object, then the X and Y positions of the object. The list ends with an address of zero. The first two bytes of the graphic are the height in pixels and the width in bytes.
Input
B Height of the actor
C Width of the actor
D Y position of the actor
E X position of the actor
IX Pointer to the list of objects
Output
F Carry flag set if the actor overlaps with an object
TestObjectOverlap B873 LD L,(IX+$00) Fetch the low byte of the address of the object.
B876 LD H,(IX+$01) Fetch the high byte of the address of the object.
B879 LD A,H Combine the bytes to check for zero.
B87A OR L
B87B RET Z Return if the address is zero (the end of the list), with the carry flag reset.
B87C LD A,(HL) Fetch the height of the object in pixels.
B87D INC HL Move to the width of the object.
B87E LD H,(HL) Fetch the width of the object in bytes.
B87F LD L,A Set the height of the object in L.
B880 LD A,H Fetch the width of the object in bytes.
B881 RLCA Multiply by eight.
B882 RLCA
B883 RLCA
B884 AND %11111000 Keep only bits 3-7.
B886 LD H,A H=the width of the object in pixels.
Compare the X positions.
B887 LD A,E Fetch the X position of the actor.
B888 SUB (IX+$02) Subtract the X position of the object.
B88B JP P,TestObjectOverlap_Right Jump to TestObjectOverlap_Right if the actor is not to the left of the object.
B88E CPL Flip the bits to get the distance from the object, less one.
B88F CP C Compare with the width of the actor.
TestObjectOverlap_Horizontal B890 JR NC,TestObjectOverlap_Next Jump to TestObjectOverlap_Next if the actor is too far away.
Compare the Y positions.
B892 LD A,D Fetch the Y position of the actor.
B893 SUB L Subtract the height of the object.
B894 SUB (IX+$03) Subtract the Y position of the object.
B897 JP P,TestObjectOverlap_Below Jump to TestObjectOverlap_Below if the feet of the actor are below the object.
B89A CPL Flip the bits to get the distance from the object, less one.
B89B CP L Compare with the height of the object.
TestObjectOverlap_Return B89C RET C Return if the actor overlaps with the object.
Move on to the next object.
TestObjectOverlap_Next B89D INC IX Move IX on four bytes.
B89F INC IX
B8A1 INC IX
B8A3 INC IX
B8A5 JR TestObjectOverlap Jump to TestObjectOverlap.
The actor is to the right of the object so compare with the width of the object.
TestObjectOverlap_Right B8A7 CP H Compare with the width of the object.
B8A8 JR TestObjectOverlap_Horizontal Jump to TestObjectOverlap_Horizontal.
The feet of the actor are below the object, so compare with the height of the actor.
TestObjectOverlap_Below B8AA CP B Compare with the height of the actor.
B8AB JR TestObjectOverlap_Return Jump to TestObjectOverlap_Return.
Prev: B81C Up: Map Next: B8AD