Prev: 51309 Up: Map Next: 51359
51322: 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 (128) 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 51322 LD HL,(23467) Fetch the size of the room in X and Y from RoomSizeX.
Take the width of the player off the size in X.
51325 LD A,L Copy the distance along x to A.
51326 SUB (IX+4) Subtract the width of the player.
51329 LD L,A Store the limit along x in L.
Take the depth of the player off the size in Y.
51330 LD A,H Copy the distance along y to A.
51331 SUB (IX+5) Subtract the depth of the player.
51334 LD H,A Store the limit along y in H.
Compare the x distance from the middle.
51335 LD A,(IX+1) Fetch the x position of the player.
51338 SUB 128 Subtract 128.
51340 JP P,TestPlayerInRoom_LimitX Jump to TestPlayerInRoom_LimitX if it is not negative.
51343 NEG Negate A.
TestPlayerInRoom_LimitX 51345 CP L Return if the player is outside along x.
51346 RET NC
Compare the y distance from the middle.
51347 LD A,(IX+2) Fetch the y position of the player.
51350 SUB 128 Subtract 128.
51352 JP P,TestPlayerInRoom_CompareY Jump to TestPlayerInRoom_CompareY if it is not negative.
51355 NEG Negate A.
TestPlayerInRoom_CompareY 51357 CP H Compare it with the limit in Y, which sets the carry flag if the player is inside.
51358 RET Return.
View the equivalent code in;
Prev: 51309 Up: Map Next: 51359