Prev: 52423 Up: Map Next: 52488
52445: 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 52445 LD A,(IX+12) Fetch the flags of the object.
52448 AND %11110000 Keep the counter of the object entering the room.
52450 RET NZ Return if the object is entering the room.
52451 BIT 0,(IX+7) Test whether the object is near an arch.
52455 RET NZ Return if it is.
52456 LD A,(23467) Fetch the size of the room in X and stash it in B from RoomSizeX.
52459 LD B,A
KeepObjectInRoomInX_Test 52460 LD A,(IX+1) Work out where the X coordinate would be, with the speed added.
52463 ADD A,C
52464 SUB 128
52466 JR NC,KeepObjectInRoomInX_Test_AddWidth Jump to KeepObjectInRoomInX_Test_AddWidth if it is not negative.
52468 NEG Make it positive.
KeepObjectInRoomInX_Test_AddWidth 52470 ADD A,(IX+4) Add the width of the object.
52473 CP B Compare it with the size of the room.
52474 JR C,KeepObjectInRoomInX_Test_Return Return if it is smaller, as the object stays in the room.
52476 SET 0,(IX+12) Flag the object as blocked in X.
52480 LD A,C Fetch the speed in X.
52481 CALL BringSpeedCloserToZero Bring it closer to zero.
52484 LD C,A Store it.
52485 JR NZ,KeepObjectInRoomInX_Test Jump to KeepObjectInRoomInX_Test if it is not zero yet.
KeepObjectInRoomInX_Test_Return 52487 RET Return.
View the equivalent code in;
Prev: 52423 Up: Map Next: 52488