Prev: C426 Up: Map Next: C497
C442: 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 C442 BIT 1,(IX+$07) Return if the object is ignored.
C446 RET NZ
C447 SET 1,(IX+$07) Flag the object to be ignored, so that it does not hit itself.
C44B LD A,(IX+$0C) Fetch the collision flags.
C44E AND %11111000 Clear the blocked flags of x, y and z.
C450 LD (IX+$0C),A Store the collision flags.
C453 LD L,$00 Write 00 to the new speeds along x and y.
C455 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.
C456 LD A,(IX+$0B) Fetch the speed along z and test whether it is zero.
C459 AND A
C45A LD H,A Copy it to H.
C45B JR Z,BlockMovement_X Jump to BlockMovement_X if it is zero.
C45D CALL StopObjectAtFloor Stop the object going through the floor.
C460 LD A,H Jump to BlockMovement_X if the speed along z is now zero.
C461 AND A
C462 JR Z,BlockMovement_X
C464 CALL BlockMovementInZ Stop the object going through other objects.
Test x against the walls of the room, then other objects.
BlockMovement_X C467 LD A,(IX+$09) Fetch the speed along x and test whether it is zero.
C46A AND A
C46B LD C,A Copy it to C.
C46C JR Z,BlockMovement_Y Jump to BlockMovement_Y if it is zero.
C46E CALL KeepObjectInRoomInX Stop the object going through the walls of the room.
C471 LD A,C Jump to BlockMovement_Y if the speed along x is now zero.
C472 AND A
C473 JR Z,BlockMovement_Y
C475 CALL BlockMovementInX Stop the object going through other objects.
Test y against the walls of the room, then other objects.
BlockMovement_Y C478 LD A,(IX+$0A) Fetch the speed along y and test whether it is zero.
C47B AND A
C47C LD L,A Copy it to L.
C47D JR Z,BlockMovement_Store Jump to BlockMovement_Store if it is zero.
C47F CALL KeepObjectInRoomInY Stop the object going through the walls of the room.
C482 LD A,L Jump to BlockMovement_Store if the speed along y is now zero.
C483 AND A
C484 JR Z,BlockMovement_Store
C486 CALL BlockMovementInY Stop the object going through other objects.
Store the new speeds and stop ignoring the object.
BlockMovement_Store C489 LD (IX+$09),C Store the new speeds along x, y and z.
C48C LD (IX+$0A),L
C48F LD (IX+$0B),H
C492 RES 1,(IX+$07) Stop ignoring the object.
C496 RET Return.
View the equivalent code in;
Prev: C426 Up: Map Next: C497