Prev: 34418 Up: Map Next: 34586
34546: Randomise Velocity
Gives a creature a new random velocity on each axis. The Y velocity is chosen first. Each velocity is either -2 or 2 or else -1 or 1. The random number comes from the refresh register.
Input
IX The creature entity
RandomiseVelocity 34546 LD A,R Fetch a random number (from the refresh register).
34548 BIT 0,A Jump to RandomiseVelocity_SlowY if bit 0 was not set.
34550 JR Z,RandomiseVelocity_SlowY
34552 AND %00000100 Keep only bit 2.
34554 SUB 2 Subtract 2 giving -2 or 2.
RandomiseVelocity_SetY 34556 LD (IX+9),A Update the Y velocity of the creature.
34559 LD A,R Fetch a random number (from the refresh register).
34561 RRA Rotate the random number right, so that bit 1 becomes bit 0.
34562 BIT 0,A Jump to RandomiseVelocity_SlowX if bit 0 was not set.
34564 JR Z,RandomiseVelocity_SlowX
34566 AND %00000100 Keep only bit 2.
34568 SUB 2 Subtract 2 giving -2 or 2.
RandomiseVelocity_SetX 34570 LD (IX+8),A Update the X velocity of the creature.
34573 RET Return.
RandomiseVelocity_SlowY 34574 AND %00000010 Keep only bit 1.
34576 SUB 1 Subtract 1 giving -1 or 1.
34578 JR RandomiseVelocity_SetY Jump to RandomiseVelocity_SetY to set the Y velocity of the creature.
RandomiseVelocity_SlowX 34580 AND %00000010 Keep only bit 1.
34582 SUB 1 Subtract 1 giving -1 or 1.
34584 JR RandomiseVelocity_SetX Jump to RandomiseVelocity_SetX to set the X velocity of the creature.
Prev: 34418 Up: Map Next: 34586