Prev: B6ED Up: Map Next: B791
B742: Block Movement In X
Used by the routine at BlockMovement.
Cuts down the distance that an object moves along x until it does not go through any other object. The speed is reduced by one each time until the object no longer overlaps the other object, or it is zero.
When the object hits another object, the two objects share their hit flags, and if the other object can be pushed, it is given the speed of this object.
Input
C Distance to move along x
IX Object record
Output
C Distance that can be moved
Try the object against each of the objects in turn.
BlockMovementInX B742 LD IY,$A76F Start with the first object record, ObjectsTable.
B746 LD B,$36 Set a counter in B of 36 objects.
BlockMovementInX_Next B748 CALL TestObjectSolid Jump to BlockMovementInX_NextObject if the other object is not in use, or is being moved.
B74B JR Z,BlockMovementInX_NextObject
B74D CALL TestOverlapInY Jump to BlockMovementInX_NextObject if the objects do not overlap along y.
B750 JR NC,BlockMovementInX_NextObject
B752 CALL TestOverlapInZ Jump to BlockMovementInX_NextObject if the objects do not overlap along z.
B755 JR NC,BlockMovementInX_NextObject
BlockMovementInX_Test B757 CALL TestOverlapInX Jump to BlockMovementInX_NextObject if the objects will not overlap along x when the object has moved.
B75A JR NC,BlockMovementInX_NextObject
The objects hit each other. Flag a hit along x and pass on the hit flags.
B75C SET 0,(IX+$0C) Flag that the object has been stopped along x.
B760 LD A,(IX+$0D) Fetch the hit flags of the object.
B763 RRCA Move bit 7 down to bit 6.
B764 AND %01000000 Keep only bit 6.
B766 OR (IY+$0D) Add the hit flags of the other object.
B769 LD (IY+$0D),A Write them to the other object.
B76C RLCA Move bit 5 of the hit flags of the other object up to bit 6.
B76D AND %01000000 Keep only bit 6.
B76F OR (IX+$0D) Add the hit flags of the object.
B772 LD (IX+$0D),A Write them to the object.
Push the other object, if it can be pushed.
B775 BIT 2,(IY+$07) Jump to BlockMovementInX_Reduce if the other object cannot be pushed.
B779 JR Z,BlockMovementInX_Reduce
B77B LD A,(IX+$09) Give the other object the speed along x of the object.
B77E LD (IY+$09),A
Step the distance closer to zero while the objects still overlap.
BlockMovementInX_Reduce B781 LD A,C Fetch the distance along x.
B782 CALL BringSpeedCloserToZero Call BringSpeedCloserToZero to step it one closer to zero.
B785 LD C,A Set the distance.
B786 RET Z Return if the distance is zero.
B787 JR BlockMovementInX_Test Jump to BlockMovementInX_Test to test again.
BlockMovementInX_NextObject B789 LD DE,$0020 Move IY on to the next object record.
B78C ADD IY,DE
B78E DJNZ BlockMovementInX_Next Decrease the counter and loop until all the objects have been tried.
B790 RET Return.
View the equivalent code in;
Prev: B6ED Up: Map Next: B791