Prev: 8672 Up: Map Next: 871A
86F2: Randomise Velocity
Gives a creature a new random velocity on each axis. The Y velocity is chosen first. Each velocity is either -02 or 02 or else -01 or 01. The random number comes from the refresh register.
Input
IX The creature entity
RandomiseVelocity 86F2 LD A,R Fetch a random number (from the refresh register).
86F4 BIT 0,A Jump to RandomiseVelocity_SlowY if bit 0 was not set.
86F6 JR Z,RandomiseVelocity_SlowY
86F8 AND %00000100 Keep only bit 2.
86FA SUB $02 Subtract 02 giving -02 or 02.
RandomiseVelocity_SetY 86FC LD (IX+$09),A Update the Y velocity of the creature.
86FF LD A,R Fetch a random number (from the refresh register).
8701 RRA Rotate the random number right, so that bit 1 becomes bit 0.
8702 BIT 0,A Jump to RandomiseVelocity_SlowX if bit 0 was not set.
8704 JR Z,RandomiseVelocity_SlowX
8706 AND %00000100 Keep only bit 2.
8708 SUB $02 Subtract 02 giving -02 or 02.
RandomiseVelocity_SetX 870A LD (IX+$08),A Update the X velocity of the creature.
870D RET Return.
RandomiseVelocity_SlowY 870E AND %00000010 Keep only bit 1.
8710 SUB $01 Subtract 01 giving -01 or 01.
8712 JR RandomiseVelocity_SetY Jump to RandomiseVelocity_SetY to set the Y velocity of the creature.
RandomiseVelocity_SlowX 8714 AND %00000010 Keep only bit 1.
8716 SUB $01 Subtract 01 giving -01 or 01.
8718 JR RandomiseVelocity_SetX Jump to RandomiseVelocity_SetX to set the X velocity of the creature.
Prev: 8672 Up: Map Next: 871A