Prev: B6DD Up: Map Next: B742
B6ED: 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 B6ED BIT 1,(IX+$07) Return if the object is already being moved.
B6F1 RET NZ
B6F2 SET 1,(IX+$07) Flag that the object is being moved.
B6F6 LD A,(IX+$0C) Fetch the collision flags.
B6F9 AND %11111000 Clear the blocked flags of x, y and z.
B6FB LD (IX+$0C),A Store the collision flags.
B6FE LD L,$00 Start with no speed along y in L and none along x in C.
B700 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.
B701 LD A,(IX+$0B) Fetch the speed along z and test whether it is zero.
B704 AND A
B705 LD H,A Copy it to H.
B706 JR Z,BlockMovement_X Jump to BlockMovement_X if it is zero.
B708 CALL StopObjectAtFloor Call StopObjectAtFloor to cut the speed down so that the object stays above the floor.
B70B LD A,H Jump to BlockMovement_X if that has left no speed.
B70C AND A
B70D JR Z,BlockMovement_X
B70F CALL BlockMovementInZ Call BlockMovementInZ to cut the speed down so that the object does not go through another object.
Test x against the walls of the room, then other objects.
BlockMovement_X B712 LD A,(IX+$09) Fetch the speed along x and test whether it is zero.
B715 AND A
B716 LD C,A Copy it to C.
B717 JR Z,BlockMovement_Y Jump to BlockMovement_Y if it is zero.
B719 CALL KeepObjectInRoomInX Call KeepObjectInRoomInX to cut the speed down so that the object stays inside the walls.
B71C LD A,C Jump to BlockMovement_Y if that has left no speed.
B71D AND A
B71E JR Z,BlockMovement_Y
B720 CALL BlockMovementInX Call BlockMovementInX to cut the speed down so that the object does not go through another object.
Test y against the walls of the room, then other objects.
BlockMovement_Y B723 LD A,(IX+$0A) Fetch the speed along y and test whether it is zero.
B726 AND A
B727 LD L,A Copy it to L.
B728 JR Z,BlockMovement_Store Jump to BlockMovement_Store if it is zero.
B72A CALL KeepObjectInRoomInY Call KeepObjectInRoomInY to cut the speed down so that the object stays inside the walls.
B72D LD A,L Jump to BlockMovement_Store if that has left no speed.
B72E AND A
B72F JR Z,BlockMovement_Store
B731 CALL BlockMovementInY Call BlockMovementInY to cut the speed down so that the object does not go through another object.
Store the new speeds and stop ignoring the object.
BlockMovement_Store B734 LD (IX+$09),C Store the new speeds along x, y and z.
B737 LD (IX+$0A),L
B73A LD (IX+$0B),H
B73D RES 1,(IX+$07) Flag that the object is not being moved.
B741 RET Return.
View the equivalent code in;
Prev: B6DD Up: Map Next: B742