Prev: 47330 Up: Map Next: 47416
47373: Keep Object In Room In Y
Used by the routine at BlockMovement.
Brings the speed along y 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
L Speed along y
IX The address of the object
Output
L The new speed along y
Return while entering or near an arch.
KeepObjectInRoomInY 47373 LD A,(IX+12) Fetch the collision flags.
47376 AND %11110000 Keep only the countdown from entering the room.
47378 RET NZ Return if the object has only just entered the room.
47379 BIT 0,(IX+7) Return if the object ignores the walls.
47383 RET NZ
47384 LD A,(42782) Fetch RoomSizeY.
47387 LD B,A Copy it to B.
Slow y until the object stays in the room.
KeepObjectInRoomInY_Test 47388 LD A,(IX+2) Fetch the y position of the object.
47391 ADD A,L Add L.
47392 SUB 128 Subtract 128.
47394 JR NC,KeepObjectInRoomInY_Compare Jump to KeepObjectInRoomInY_Compare if that is not negative.
47396 NEG Negate A.
KeepObjectInRoomInY_Compare 47398 ADD A,(IX+5) Add the half size of the object, to get the distance of its edge from the middle.
47401 CP B Return if the edge is inside the limit.
47402 JR C,KeepObjectInRoomInY_Done
47404 SET 1,(IX+12) Flag that the object has been stopped along y.
47408 LD A,L Copy L to A.
47409 CALL BringSpeedCloserToZero Call BringSpeedCloserToZero.
47412 LD L,A Copy it to L.
47413 JR NZ,KeepObjectInRoomInY_Test Jump to KeepObjectInRoomInY_Test to test again, unless the distance is zero.
KeepObjectInRoomInY_Done 47415 RET Return.
View the equivalent code in;
Prev: 47330 Up: Map Next: 47416