Prev: B8E2 Up: Map Next: B938
B90D: 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 B90D LD A,(IX+$0C) Fetch the collision flags.
B910 AND %11110000 Keep only the countdown from entering the room.
B912 RET NZ Return if the object has only just entered the room.
B913 BIT 0,(IX+$07) Return if the object ignores the walls.
B917 RET NZ
B918 LD A,($A71E) Fetch RoomSizeY.
B91B LD B,A Copy it to B.
Slow y until the object stays in the room.
KeepObjectInRoomInY_Test B91C LD A,(IX+$02) Fetch the y position of the object.
B91F ADD A,L Add L.
B920 SUB $80 Subtract 80.
B922 JR NC,KeepObjectInRoomInY_Compare Jump to KeepObjectInRoomInY_Compare if that is not negative.
B924 NEG Negate A.
KeepObjectInRoomInY_Compare B926 ADD A,(IX+$05) Add the half size of the object, to get the distance of its edge from the middle.
B929 CP B Return if the edge is inside the limit.
B92A JR C,KeepObjectInRoomInY_Done
B92C SET 1,(IX+$0C) Flag that the object has been stopped along y.
B930 LD A,L Copy L to A.
B931 CALL BringSpeedCloserToZero Call BringSpeedCloserToZero.
B934 LD L,A Copy it to L.
B935 JR NZ,KeepObjectInRoomInY_Test Jump to KeepObjectInRoomInY_Test to test again, unless the distance is zero.
KeepObjectInRoomInY_Done B937 RET Return.
View the equivalent code in;
Prev: B8E2 Up: Map Next: B938