Prev: DDFC Up: Map Next: DE59
DE0D: Set Direction From Velocity
Used by the routines at UpdateGhost, UpdateSpore and UpdateVillageItem.
Makes an object face the direction that it is moving in, and tests whether it can move that way. The direction along the X axis is used first, and then the one along the Y axis, so that an object that is moving along both axes ends up facing along the Y axis (if the velocity along that axis is not zero).
Input
IX Object
Face along the X axis first.
SetDirectionFromVelocity DE0D LD A,(IX+$0A) Jump to SetDirectionFromVelocity_Y if the velocity along the X axis is zero.
DE10 AND A
DE11 JR Z,SetDirectionFromVelocity_Y
DE13 LD A,$40 Face right...
DE15 JP P,SetDirectionFromVelocity_X
DE18 OR %10000000 ... or face left, if the velocity is negative.
SetDirectionFromVelocity_X DE1A LD C,A Keep the direction.
DE1B LD A,(IX+$06) Set the direction of the object.
DE1E AND $3F
DE20 OR C
DE21 LD (IX+$06),A
DE24 LD A,(IX+$0B) Stash the velocity along the Y axis, and set it to zero.
DE27 PUSH AF
DE28 LD (IX+$0B),$00
DE2C CALL TestMove Test whether the object can move that way.
DE2F POP AF Restore the velocity along the Y axis from the stack.
DE30 LD (IX+$0B),A
Then face along the Y axis.
SetDirectionFromVelocity_Y DE33 LD A,(IX+$0B) Return if the velocity along the Y axis is zero.
DE36 AND A
DE37 RET Z
DE38 LD A,$00 Face up the screen...
DE3A JP P,SetDirectionFromVelocity_Set
DE3D OR %10000000 ... or face down the screen, if the velocity is negative.
SetDirectionFromVelocity_Set DE3F LD C,A Keep the direction.
DE40 LD A,(IX+$06) Set the direction of the object.
DE43 AND $3F
DE45 OR C
DE46 LD (IX+$06),A
DE49 LD A,(IX+$0A) Keep the velocity along the X axis, and set it to zero.
DE4C PUSH AF
DE4D LD (IX+$0A),$00
DE51 CALL TestMove_Keep Test whether the object can move that way.
DE54 POP AF Restore the velocity along the X axis from the stack.
DE55 LD (IX+$0A),A
DE58 RET Return.
Prev: DDFC Up: Map Next: DE59