Prev: 42440 Up: Map Next: 42497
42445: Choose Velocity
Used by the routines at HandlerChooseNastie and HandlerWanderingNastie.
Chooses the velocity for a wandering actor. If it is moving then it is stopped (by StopActor). If it has stopped then it is given a random X velocity and a random Y velocity from VelocityTable, and the sprite is made to face the way it is going.
Input
IX Actor record
ChooseVelocity 42445 LD A,(IX+6) Fetch the X velocity of the actor.
42448 OR (IX+7) Combine it with the Y velocity.
42451 JR NZ,StopActor Jump to StopActor to stop the actor if it is moving.
Choose the X velocity.
42453 LD A,(38549) Fetch the random seed from RandomNumber.
42456 AND %00000111 Keep only bits 0-2.
42458 LD L,A Stash the velocity index in L.
42459 LD H,0 Clear H.
42461 LD BC,42497 Point BC at the table of velocities at VelocityTable.
42464 ADD HL,BC Add the table address to get the address of the velocity.
42465 LD A,(HL) Fetch the velocity from the table.
42466 LD (IX+6),A Set the X velocity of the actor.
42469 BIT 7,A Jump to ChooseVelocity_Right if the actor is moving right.
42471 JR Z,ChooseVelocity_Right
42473 RES 1,(IX+0) Reset bit 1 of the sprite ID so that the actor faces left.
Choose the Y velocity.
ChooseVelocity_Y 42477 LD A,(23672) Fetch the low byte of FRAMES.
42480 AND %00000111 Keep only bits 0-2.
42482 LD L,A Stash the velocity index in L.
42483 LD H,0 Clear H.
42485 ADD HL,BC Add the table address to get the address of the velocity.
42486 LD A,(HL) Fetch the velocity from the table.
42487 LD (IX+7),A Set the Y velocity of the actor.
42490 RET Return.
The actor is moving to the right.
ChooseVelocity_Right 42491 SET 1,(IX+0) Set bit 1 of the sprite ID so that the actor faces right.
42495 JR ChooseVelocity_Y Jump to ChooseVelocity_Y to choose the Y velocity.
Prev: 42440 Up: Map Next: 42497