Prev: 36758 Up: Map Next: 36874
36810: 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 2 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 (88 across and 104 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 36810 PUSH DE Stash the moves on the stack.
36811 LD A,E Fetch the X move.
36812 ADD A,(IX+3) Add the X position of the entity.
36815 LD E,A Keep the new X position in E.
36816 LD D,(IX+4) Fetch the Y position of the entity.
36819 LD B,16 B=16 (the flag for the X axis).
36821 CALL CheckRoomBounds_Position Call CheckRoomBounds_Position to check whether the position is inside the room.
36824 POP DE Restore the moves from the stack.
36825 PUSH DE Stash it on the stack again.
36826 LD E,(IX+3) Fetch the X position of the entity.
36829 LD A,D Fetch the Y move.
36830 ADD A,(IX+4) Add the Y position of the entity.
36833 LD D,A Keep the new Y position in D.
36834 LD B,32 B=32 (the flag for the Y axis).
36836 CALL CheckRoomBounds_Position Call CheckRoomBounds_Position to check whether the position is inside the room.
36839 POP DE Restore the moves from the stack.
36840 RET Return.
Clears a flag if a position is inside the room.
CheckRoomBounds_Position 36841 LD HL,24093 Point HL at the room width at CurrentRoom_Width.
36844 LD A,E Fetch the X position to check.
36845 SUB 88 Subtract 88 (the horizontal centre of the room).
36847 JP P,CheckRoomBounds_Width Jump to CheckRoomBounds_Width if the result is positive.
36850 NEG Make the result positive.
CheckRoomBounds_Width 36852 CP (HL) Compare it with the width of the room.
36853 RET NC Return if it is outside.
36854 INC HL Move HL on to the height of the room.
36855 LD A,D Fetch the Y position to check.
36856 SUB 104 Subtract 104 (the vertical centre of the room).
36858 JP P,CheckRoomBounds_Height Jump to CheckRoomBounds_Height if the result is positive.
36861 NEG Make the result positive.
CheckRoomBounds_Height 36863 CP (HL) Compare it with the height of the room.
36864 RET NC Return if it is outside.
36865 LD A,B Fetch the flag for the axis.
36866 CPL Invert the flag, to make a mask.
36867 AND (IX+2) Clear the flag in offset 2 of the entity.
36870 LD (IX+2),A Write the result back to offset 2.
36873 RET Return.
Prev: 36758 Up: Map Next: 36874