Prev: 47308 Up: Map Next: 47373
47330: Keep Object In Room In X
Used by the routine at BlockMovement.
Brings the speed along 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 along x
IX The address of the object
Output
C The new speed along x
Return while entering or near an arch.
KeepObjectInRoomInX 47330 LD A,(IX+12) Fetch the collision flags.
47333 AND %11110000 Keep only the countdown from entering the room.
47335 RET NZ Return if the object has only just entered the room.
47336 BIT 0,(IX+7) Return if the object ignores the walls.
47340 RET NZ
47341 LD A,(42781) Fetch RoomSizeX.
47344 LD B,A Copy it to B.
Slow x until the object stays in the room.
KeepObjectInRoomInX_Test 47345 LD A,(IX+1) Fetch the x position of the object.
47348 ADD A,C Add C.
47349 SUB 128 Subtract 128.
47351 JR NC,KeepObjectInRoomInX_Compare Jump to KeepObjectInRoomInX_Compare if that is not negative.
47353 NEG Negate A.
KeepObjectInRoomInX_Compare 47355 ADD A,(IX+4) Add the half size of the object, to get the distance of its edge from the middle.
47358 CP B Return if the edge is inside the limit.
47359 JR C,KeepObjectInRoomInX_Done
47361 SET 0,(IX+12) Flag that the object has been stopped along x.
47365 LD A,C Copy C to A.
47366 CALL BringSpeedCloserToZero Call BringSpeedCloserToZero.
47369 LD C,A Copy it to C.
47370 JR NZ,KeepObjectInRoomInX_Test Jump to KeepObjectInRoomInX_Test to test again, unless the distance is zero.
KeepObjectInRoomInX_Done 47372 RET Return.
View the equivalent code in;
Prev: 47308 Up: Map Next: 47373