Prev: C86D Up: Map Next: C89F
C87A: Test Player In Room
Used by the routines at HandlePickupAndDrop and HandlePlayerLegs.
Tests whether the player is inside the room. The distance from the middle of the room (80) has to be smaller than the distance to the wall, less the width of the player along x and less the depth of the player along y.
Input
IX The address of the object
Output
F Carry flag set if the player is inside the room
Limits from the wall distances.
TestPlayerInRoom C87A LD HL,($5BAB) Fetch the size of the room in X and Y from RoomSizeX.
Take the width of the player off the size in X.
C87D LD A,L Copy the distance along x to A.
C87E SUB (IX+$04) Subtract the width of the player.
C881 LD L,A Store the limit along x in L.
Take the depth of the player off the size in Y.
C882 LD A,H Copy the distance along y to A.
C883 SUB (IX+$05) Subtract the depth of the player.
C886 LD H,A Store the limit along y in H.
Compare the x distance from the middle.
C887 LD A,(IX+$01) Fetch the x position of the player.
C88A SUB $80 Subtract 80.
C88C JP P,TestPlayerInRoom_LimitX Jump to TestPlayerInRoom_LimitX if it is not negative.
C88F NEG Negate A.
TestPlayerInRoom_LimitX C891 CP L Return if the player is outside along x.
C892 RET NC
Compare the y distance from the middle.
C893 LD A,(IX+$02) Fetch the y position of the player.
C896 SUB $80 Subtract 80.
C898 JP P,TestPlayerInRoom_CompareY Jump to TestPlayerInRoom_CompareY if it is not negative.
C89B NEG Negate A.
TestPlayerInRoom_CompareY C89D CP H Compare it with the limit in Y, which sets the carry flag if the player is inside.
C89E RET Return.
View the equivalent code in;
Prev: C86D Up: Map Next: C89F