Prev: 8F96 Up: Map Next: 900A
8FCA: Check Room Bounds
Used by the routine at ControlPlayer.
Checks whether an entity could move along each axis without leaving the room. If the position it would be at is inside the room then the flag for the axis in offset 02 is cleared (bit 4 for X and bit 5 for Y), so that ApplyMovement will move it. The position is inside the room when the distance from the centre of the room (58 across and 68 down) is less than the width and the height in CurrentRoom_Width.
Input
DE The pixels to move (X in E and Y in D)
IX The entity
CheckRoomBounds 8FCA PUSH DE Stash the moves on the stack.
8FCB LD A,E Fetch the X move.
8FCC ADD A,(IX+$03) Add the X position of the entity.
8FCF LD E,A Keep the new X position in E.
8FD0 LD D,(IX+$04) Fetch the Y position of the entity.
8FD3 LD B,$10 B=10 (the flag for the X axis).
8FD5 CALL CheckRoomBounds_Position Call CheckRoomBounds_Position to check whether the position is inside the room.
8FD8 POP DE Restore the moves from the stack.
8FD9 PUSH DE Stash it on the stack again.
8FDA LD E,(IX+$03) Fetch the X position of the entity.
8FDD LD A,D Fetch the Y move.
8FDE ADD A,(IX+$04) Add the Y position of the entity.
8FE1 LD D,A Keep the new Y position in D.
8FE2 LD B,$20 B=20 (the flag for the Y axis).
8FE4 CALL CheckRoomBounds_Position Call CheckRoomBounds_Position to check whether the position is inside the room.
8FE7 POP DE Restore the moves from the stack.
8FE8 RET Return.
Clears a flag if a position is inside the room.
CheckRoomBounds_Position 8FE9 LD HL,$5E1D Point HL at the room width at CurrentRoom_Width.
8FEC LD A,E Fetch the X position to check.
8FED SUB $58 Subtract 58 (the horizontal centre of the room).
8FEF JP P,CheckRoomBounds_Width Jump to CheckRoomBounds_Width if the result is positive.
8FF2 NEG Make the result positive.
CheckRoomBounds_Width 8FF4 CP (HL) Compare it with the width of the room.
8FF5 RET NC Return if it is outside.
8FF6 INC HL Move HL on to the height of the room.
8FF7 LD A,D Fetch the Y position to check.
8FF8 SUB $68 Subtract 68 (the vertical centre of the room).
8FFA JP P,CheckRoomBounds_Height Jump to CheckRoomBounds_Height if the result is positive.
8FFD NEG Make the result positive.
CheckRoomBounds_Height 8FFF CP (HL) Compare it with the height of the room.
9000 RET NC Return if it is outside.
9001 LD A,B Fetch the flag for the axis.
9002 CPL Invert the flag, to make a mask.
9003 AND (IX+$02) Clear the flag in offset 02 of the entity.
9006 LD (IX+$02),A Write the result back to offset 02.
9009 RET Return.
Prev: 8F96 Up: Map Next: 900A