Prev: B742 Up: Map Next: B7E0
B791: Block Movement In Y
Used by the routine at BlockMovement.
Cuts down the distance that an object moves along y until it does not go through any other object, in the same way as BlockMovementInX does for x.
Input
L Distance to move along y
IX Object record
Output
L Distance that can be moved
Try the object against each of the objects in turn.
BlockMovementInY B791 LD IY,$A76F Start with the first object record, ObjectsTable.
B795 LD B,$36 Set a counter in B of 36 objects.
BlockMovementInY_Next B797 CALL TestObjectSolid Jump to BlockMovementInY_NextObject if the other object is not in use, or is being moved.
B79A JR Z,BlockMovementInY_NextObject
B79C CALL TestOverlapInX Jump to BlockMovementInY_NextObject if the objects do not overlap along x.
B79F JR NC,BlockMovementInY_NextObject
B7A1 CALL TestOverlapInZ Jump to BlockMovementInY_NextObject if the objects do not overlap along z.
B7A4 JR NC,BlockMovementInY_NextObject
BlockMovementInY_Test B7A6 CALL TestOverlapInY Jump to BlockMovementInY_NextObject if the objects will not overlap along y when the object has moved.
B7A9 JR NC,BlockMovementInY_NextObject
The objects hit each other. Flag a hit along y and pass on the hit flags.
B7AB SET 1,(IX+$0C) Flag that the object has been stopped along y.
B7AF LD A,(IX+$0D) Fetch the hit flags of the object.
B7B2 RRCA Move bit 7 down to bit 6.
B7B3 AND %01000000 Keep only bit 6.
B7B5 OR (IY+$0D) Add the hit flags of the other object.
B7B8 LD (IY+$0D),A Write them to the other object.
B7BB RLCA Move bit 5 of the hit flags of the other object up to bit 6.
B7BC AND %01000000 Keep only bit 6.
B7BE OR (IX+$0D) Add the hit flags of the object.
B7C1 LD (IX+$0D),A Write them to the object.
Push the other object, if it can be pushed.
B7C4 BIT 2,(IY+$07) Jump to BlockMovementInY_Reduce if the other object cannot be pushed.
B7C8 JR Z,BlockMovementInY_Reduce
B7CA LD A,(IX+$0A) Give the other object the speed along y of the object.
B7CD LD (IY+$0A),A
Step the distance closer to zero while the objects still overlap.
BlockMovementInY_Reduce B7D0 LD A,L Fetch the distance along y.
B7D1 CALL BringSpeedCloserToZero Call BringSpeedCloserToZero to step it one closer to zero.
B7D4 LD L,A Set the distance.
B7D5 RET Z Return if the distance is zero.
B7D6 JR BlockMovementInY_Test Jump to BlockMovementInY_Test to test again.
BlockMovementInY_NextObject B7D8 LD DE,$0020 Move IY on to the next object record.
B7DB ADD IY,DE
B7DD DJNZ BlockMovementInY_Next Decrease the counter and loop until all the objects have been tried.
B7DF RET Return.
View the equivalent code in;
Prev: B742 Up: Map Next: B7E0