Prev: DD99 Up: Map Next: DDFC
DDCF: Choose Random Velocity
Used by the routines at UpdateSpore and UpdateVillageItem.
Chooses a new random velocity along both axes for an object when the timer has run out (the lowest six bits of the direction and timer) or when the object is not moving. The velocity along each axis is an even number, chosen from the random seeds. A new timer is set from the memory refresh register.
Input
B Number of random bits to use for each velocity
IX Object
ChooseRandomVelocity DDCF DEC (IX+$06) Count down the timer, and jump to ChooseRandomVelocity_Choose if it has run out.
DDD2 LD A,(IX+$06)
DDD5 AND $3F
DDD7 JR Z,ChooseRandomVelocity_Choose
DDD9 LD A,(IX+$0A) Return if the object is moving.
DDDC OR (IX+$0B)
DDDF RET NZ
ChooseRandomVelocity_Choose DDE0 LD A,($BBAA) Choose the velocity along the X axis from the first random seed.
DDE3 LD C,A
DDE4 CALL ChooseVelocity
DDE7 LD (IX+$0A),A
DDEA LD A,($BBAB) Choose the velocity along the Y axis from the second random seed.
DDED LD C,A
DDEE CALL ChooseVelocity
DDF1 LD (IX+$0B),A
DDF4 LD A,R Set a random timer.
DDF6 AND $3F
DDF8 LD (IX+$06),A
DDFB RET Return.
Prev: DD99 Up: Map Next: DDFC