Prev: 9B89 Up: Map Next: 9C1A
9BB9: Update Whirler Entity
Updates an entity of the type 11 which is made from the third kind of creature at CreatureTemplates. Field 23 counts down the frames between random changes of its speed and its direction.
Input
IX The entity
UpdateWhirlerEntity 9BB9 CALL IncreaseEntityCounter Call IncreaseEntityCounter.
9BBC BIT 7,(IX+$23) Test bit 7 of field 23 of the entity.
9BC0 CALL NZ,ResetEntityMovement Call ResetEntityMovement if it is set.
9BC3 DEC (IX+$23) Decrease field 23 of the entity by one.
9BC6 JP NZ,UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity unless it is zero.
9BC9 LD A,($5F9B) Fetch the random number from 5F9B.
9BCC LD (IX+$1D),$30 Set field 1D of the entity to 30.
9BD0 RLA Rotate bit 7 of the random number into the carry flag.
9BD1 JR C,UpdateWhirlerEntity_Speed Jump to UpdateWhirlerEntity_Speed if it is set.
9BD3 LD (IX+$1D),$63 Set field 1D of the entity to 63.
UpdateWhirlerEntity_Speed 9BD7 AND %11100000 Use bits 5-7 of the rotated value.
9BD9 JR NZ,UpdateWhirlerEntity_Delay Jump to UpdateWhirlerEntity_Delay unless they are all zero.
9BDB LD (IX+$12),$03 Set field 12 of the entity to 03.
UpdateWhirlerEntity_Delay 9BDF LD A,($5F9A) Fetch the low byte of the seed from RandomNumber_Seed and keep it in B.
9BE2 LD B,A
9BE3 AND %00111111 Use bits 0-5.
9BE5 LD (IX+$23),A Store it as the new delay in field 23 of the entity.
9BE8 LD A,B Fetch the random number.
9BE9 AND %11000000 Use bits 6-7.
9BEB JR NZ,UpdateWhirlerEntity_Direction Jump to UpdateWhirlerEntity_Direction unless they are both zero.
9BED LD (IX+$10),$00 Set the speed to 00.
9BF1 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
UpdateWhirlerEntity_Direction 9BF4 RRA Shift bits 6-7 of the random number...
9BF5 RRA ...down to bits 4-5.
9BF6 AND %00110000 Use bits 4-5.
9BF8 ADD A,$10 Add 10.
9BFA LD B,A Keep the new value in B.
9BFB LD A,(IX+$10) Fetch the speed.
9BFE AND %00001111 Use bits 0-3.
9C00 OR B Combine them with the new value.
9C01 LD (IX+$10),A Set the speed.
9C04 LD A,($5F9B) Fetch the random number from 5F9B.
9C07 AND %00001111 Use bits 0-3.
9C09 LD (IX+$20),A Set field 20 of the entity, the wanted heading.
9C0C CALL FacePlayer Call FacePlayer to choose the direction towards the player.
9C0F LD A,(IX+$20) Read field 20 of the entity.
9C12 OR %10000000 Set bit 7.
9C14 LD (IX+$11),A Set the heading.
9C17 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
Prev: 9B89 Up: Map Next: 9C1A