Prev: 50214 Up: Map Next: 50327
50242: Block Movement
Used by the routines at ApplyGravityAndMove and MovePlayer.
Stops an object moving through the walls of the room or through other objects. The speeds along x, y and z of the object are each brought closer to zero until the object can move without hitting anything. Whichever direction is hit is flagged in the low bits of the collision flags: bit 0 for x, bit 1 for y and bit 2 for z. For z that means the object is standing on something. An object that is flagged to be ignored is not adjusted.
Input
IX The address of the object
Ignore the object so that it does not hit itself, and clear the blocked flags.
BlockMovement 50242 BIT 1,(IX+7) Return if the object is ignored.
50246 RET NZ
50247 SET 1,(IX+7) Flag the object to be ignored, so that it does not hit itself.
50251 LD A,(IX+12) Fetch the collision flags.
50254 AND %11111000 Clear the blocked flags of x, y and z.
50256 LD (IX+12),A Store the collision flags.
50259 LD L,0 Write 0 to the new speeds along x and y.
50261 LD C,L
The new speeds are kept in H for z, C for x and L for y. Test z against the floor, then other objects.
50262 LD A,(IX+11) Fetch the speed along z and test whether it is zero.
50265 AND A
50266 LD H,A Copy it to H.
50267 JR Z,BlockMovement_X Jump to BlockMovement_X if it is zero.
50269 CALL StopObjectAtFloor Stop the object going through the floor.
50272 LD A,H Jump to BlockMovement_X if the speed along z is now zero.
50273 AND A
50274 JR Z,BlockMovement_X
50276 CALL BlockMovementInZ Stop the object going through other objects.
Test x against the walls of the room, then other objects.
BlockMovement_X 50279 LD A,(IX+9) Fetch the speed along x and test whether it is zero.
50282 AND A
50283 LD C,A Copy it to C.
50284 JR Z,BlockMovement_Y Jump to BlockMovement_Y if it is zero.
50286 CALL KeepObjectInRoomInX Stop the object going through the walls of the room.
50289 LD A,C Jump to BlockMovement_Y if the speed along x is now zero.
50290 AND A
50291 JR Z,BlockMovement_Y
50293 CALL BlockMovementInX Stop the object going through other objects.
Test y against the walls of the room, then other objects.
BlockMovement_Y 50296 LD A,(IX+10) Fetch the speed along y and test whether it is zero.
50299 AND A
50300 LD L,A Copy it to L.
50301 JR Z,BlockMovement_Store Jump to BlockMovement_Store if it is zero.
50303 CALL KeepObjectInRoomInY Stop the object going through the walls of the room.
50306 LD A,L Jump to BlockMovement_Store if the speed along y is now zero.
50307 AND A
50308 JR Z,BlockMovement_Store
50310 CALL BlockMovementInY Stop the object going through other objects.
Store the new speeds and stop ignoring the object.
BlockMovement_Store 50313 LD (IX+9),C Store the new speeds along x, y and z.
50316 LD (IX+10),L
50319 LD (IX+11),H
50322 RES 1,(IX+7) Stop ignoring the object.
50326 RET Return.
View the equivalent code in;
Prev: 50214 Up: Map Next: 50327