Prev: DED3 Up: Map Next: DF97
DF34: Test Move Down
Tests the move of an object that is facing down the screen (along the negative Y axis), in the same way as TestMoveUp. The front edge is at the Y position minus the half depth of the object, and it is tested from the left corner to the right corner. Each cell is tested by TestCellMovingDown.
Input
IX Object
Output
F The carry flag is set if there was a collision
TestMoveDown DF34 LD L,(IX+$01) Fetch the X position of the object.
DF37 LD H,(IX+$02)
DF3A LD C,(IX+$08) Fetch the half width of the object.
DF3D LD B,$00
DF3F AND A Subtract it to get the left edge, and keep it in DE.
DF40 SBC HL,BC
DF42 EX DE,HL
DF43 LD L,(IX+$03) Fetch the Y position of the object.
DF46 LD H,(IX+$04)
DF49 LD C,(IX+$09) Fetch the half depth of the object.
DF4C AND A Subtract it to get the front edge.
DF4D SBC HL,BC
DF4F PUSH DE Save the edges.
DF50 PUSH HL
DF51 CALL TestCellMovingDown Check whether the front left corner of the object hits a wall.
DF54 POP DE Get the edges back, with the registers swapped over.
DF55 POP HL
DF56 RET C Return if the object hit a wall.
DF57 PUSH HL Save the edges again.
DF58 PUSH DE
DF59 LD C,(IX+$08) Work out the width of the object.
DF5C SLA C
DF5E LD B,$00
DF60 LD A,H Keep the cell of the left edge.
DF61 ADD HL,BC Work out the right edge.
DF62 CP H Jump to TestMoveDown_SameCell if the right edge is in the same cell as the left edge.
DF63 JR Z,TestMoveDown_SameCell
DF65 EX DE,HL Use the right edge.
DF66 CALL TestCellMovingDown Check whether the front right corner of the object hits a wall.
DF69 POP HL Get the edges back.
DF6A POP DE
DF6B RET C Return if the object hit a wall.
Check the cells after the move.
DF6C LD C,(IX+$0B) Fetch the velocity along the Y axis.
DF6F LD B,$FF Make it a negative word in BC.
Work out the position that the velocity takes the front edge to, and return if it is in the same cell.
DF71 LD A,H Find the front edge after the move.
DF72 ADD HL,BC
DF73 CP H Return if it is in the same cell.
DF74 RET Z
DF75 PUSH DE Save the edges.
DF76 PUSH HL
DF77 CALL TestCellMovingDown Check whether the front left corner hits a wall in the next cell.
DF7A POP DE Get the edges back, with the registers swapped over.
DF7B POP HL
DF7C RET C Return if the object hit a wall.
DF7D LD C,(IX+$08) Work out the width of the object.
DF80 SLA C
DF82 LD B,$00
DF84 ADD HL,BC Work out the right edge.
DF85 EX DE,HL Use the right edge.
Check whether the front right corner hits a wall in the next cell.
DF86 JP TestCellMovingDown Jump to TestCellMovingDown.
The left and right edges are in the same cell.
TestMoveDown_SameCell DF89 POP HL Get the edges back.
DF8A POP DE
Fetch the velocity along the Y axis, which is negative.
DF8B LD C,(IX+$0B) Fetch the velocity along the Y axis.
DF8E LD B,$FF Make it a negative word in BC.
Work out the position that the velocity takes the front edge to, and return if it is in the same cell.
DF90 LD A,H Find the front edge after the move.
DF91 ADD HL,BC
DF92 CP H Return if it is in the same cell.
DF93 RET Z
Check whether the front edge hits a wall in the next cell.
DF94 JP TestCellMovingDown Jump to TestCellMovingDown.
View the equivalent code in;
Prev: DED3 Up: Map Next: DF97