Prev: 50240 Up: Map Next: 50376
50339: 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 50339 LD HL,(42781) Fetch the limits of the room, RoomSizeX along x and RoomSizeY along y.
Take the half size along x off the limit along x.
50342 LD A,L Copy the distance along x to A.
50343 SUB (IX+4) Subtract the width of the player.
50346 LD L,A Store the limit along x in L.
Take the half size along y off the limit along y.
50347 LD A,H Copy the distance along y to A.
50348 SUB (IX+5) Subtract the depth of the player.
50351 LD H,A Store the limit along y in H.
Compare the x distance from the middle.
50352 LD A,(IX+1) Fetch the x position of the object.
Take away the middle of the room, 128, and jump to TestPlayerInRoom_LimitX if the distance is not negative.
50355 SUB 128 Subtract 128.
50357 JP P,TestPlayerInRoom_LimitX Jump to TestPlayerInRoom_LimitX if the sign flag is clear.
50360 NEG Negate A.
TestPlayerInRoom_LimitX 50362 CP L Return if the player is outside along x.
50363 RET NC
Compare the y distance from the middle.
50364 LD A,(IX+2) Fetch the y position of the object.
Take away the middle of the room, 128, and jump to TestPlayerInRoom_LimitY if the distance is not negative.
50367 SUB 128 Subtract 128.
50369 JP P,TestPlayerInRoom_LimitY Jump to TestPlayerInRoom_LimitY if the sign flag is clear.
50372 NEG Negate A.
TestPlayerInRoom_LimitY 50374 CP H Compare it with the limit along y.
50375 RET Return.
View the equivalent code in;
Prev: 50240 Up: Map Next: 50376