Prev: CCC7 Up: Map Next: CD08
CCDD: Keep Object In Room In X
Used by the routine at BlockMovement.
Brings the speed in X of an object closer to zero until the object stays within the walls of the room. Nothing is done while the object is entering the room, or while it is near an arch, as it can then go out through the wall.
Input
C Speed in X
IX Address of the object
Output
C The new speed in X
Slow the X speed until the object stays inside the walls.
KeepObjectInRoomInX CCDD LD A,(IX+$0C) Fetch the flags of the object.
CCE0 AND %11110000 Keep the counter of the object entering the room.
CCE2 RET NZ Return if the object is entering the room.
CCE3 BIT 0,(IX+$07) Test whether the object is near an arch.
CCE7 RET NZ Return if it is.
CCE8 LD A,($5BAB) Fetch the size of the room in X and stash it in B from RoomSizeX.
CCEB LD B,A
KeepObjectInRoomInX_Test CCEC LD A,(IX+$01) Work out where the X coordinate would be, with the speed added.
CCEF ADD A,C
CCF0 SUB $80
CCF2 JR NC,KeepObjectInRoomInX_Test_AddWidth Jump to KeepObjectInRoomInX_Test_AddWidth if it is not negative.
CCF4 NEG Make it positive.
KeepObjectInRoomInX_Test_AddWidth CCF6 ADD A,(IX+$04) Add the width of the object.
CCF9 CP B Compare it with the size of the room.
CCFA JR C,KeepObjectInRoomInX_Test_Return Return if it is smaller, as the object stays in the room.
CCFC SET 0,(IX+$0C) Flag the object as blocked in X.
CD00 LD A,C Fetch the speed in X.
CD01 CALL BringSpeedCloserToZero Bring it closer to zero.
CD04 LD C,A Store it.
CD05 JR NZ,KeepObjectInRoomInX_Test Jump to KeepObjectInRoomInX_Test if it is not zero yet.
KeepObjectInRoomInX_Test_Return CD07 RET Return.
View the equivalent code in;
Prev: CCC7 Up: Map Next: CD08