Prev: 9CA3 Up: Map Next: 9D67
9CBA: Update Saucer Entity
Updates an entity of the type 09 which is made from the fourth kind of creature at CreatureTemplates. On odd frames it turns towards the player, and on average once in every 20 frames it fires a new entity of the type 0E from the position of this one, if there is a free entity to use.
Input
IX The entity
UpdateSaucerEntity 9CBA CALL IncreaseEntityCounter Call IncreaseEntityCounter.
9CBD LD A,($A2DD) Fetch the low byte of the frame counter from FrameCounter.
9CC0 RRA Rotate bit 0 into the carry flag.
9CC1 CALL C,FacePlayer Call FacePlayer on odd frames to choose the direction towards the player.
9CC4 LD B,$02 Set the size of the step to 02.
9CC6 CALL TurnEntity Call TurnEntity to turn the entity towards the wanted heading.
9CC9 LD A,($5F9A) Fetch the low byte of the seed from RandomNumber_Seed.
9CCC AND %00011111 Use bits 0-4.
9CCE JR NZ,UpdateSaucerEntity_Speed Jump to UpdateSaucerEntity_Speed unless they are all zero.
9CD0 PUSH IX Copy the address of the entity into IY (using the stack).
9CD2 POP IY
9CD4 LD IX,$B5B2 Point IX at EntitiesEntity_03.
9CD8 LD B,$02 Look at 02 entities.
9CDA CALL FindFreeEntity Call FindFreeEntity to find a free entity.
9CDD JR NZ,UpdateSaucerEntity_Speed Jump to UpdateSaucerEntity_Speed if there is not one.
9CDF CALL PlayShotSound Call PlayShotSound.
9CE2 CALL ClearEntity Call ClearEntity to clear the new entity.
9CE5 LD (IX+$00),$0E Set the type of the new entity to 0E.
9CE9 LD (IX+$01),$20 Set the frame of the new entity to 20.
9CED LD BC,$0008 BC is 08.
9CF0 LD H,(IY+$02) Fetch the first byte of the first coordinate of this entity.
9CF3 LD L,(IY+$03) Fetch the second byte of the first coordinate of this entity.
9CF6 ADD HL,BC Add 08.
9CF7 LD (IX+$02),H Store the first byte of the first coordinate of the new entity.
9CFA LD (IX+$03),L Store the second byte of the first coordinate of the new entity.
9CFD LD H,(IY+$05) Fetch the first byte of the second coordinate of this entity.
9D00 LD L,(IY+$06) Fetch the second byte of the second coordinate of this entity.
9D03 ADD HL,BC Add 08.
9D04 LD (IX+$05),H Store the first byte of the second coordinate of the new entity.
9D07 LD (IX+$06),L Store the second byte of the second coordinate of the new entity.
9D0A LD C,$03 C is 03.
9D0C LD H,(IY+$08) Fetch the first byte of the third coordinate of this entity.
9D0F LD L,(IY+$09) Fetch the second byte of the third coordinate of this entity.
9D12 LD (IX+$08),H Store the first byte of the third coordinate of the new entity.
9D15 LD (IX+$09),L Store the second byte of the third coordinate of the new entity.
9D18 LD (IX+$0B),$04 Set the first size of the new entity to 04.
9D1C LD (IX+$0C),$04 Set the second size of the new entity to 04.
9D20 LD (IX+$0D),$04 Set the third size of the new entity to 04.
9D24 CALL SetUpShotSprite Call SetUpShotSprite to set up the sprite of the new entity.
9D27 LD A,($5F9A) Fetch the low byte of the seed from RandomNumber_Seed.
9D2A AND %00001111 Use bits 0-3.
9D2C LD (IX+$20),A Set field 20 of the new entity, the wanted heading.
9D2F CALL FacePlayer Call FacePlayer to choose the direction towards the player.
9D32 LD A,(IX+$20) Read field 20 of the new entity.
9D35 OR %10000000 Set bit 7.
9D37 LD (IX+$11),A Store it in field 11 of the new entity, the heading.
9D3A PUSH IY Copy the address of this entity back into IX (using the stack).
9D3C POP IX
UpdateSaucerEntity_Speed 9D3E LD A,(IX+$12) Read field 12 of the entity.
9D41 AND A Test it.
9D42 JR NZ,UpdateSaucerEntity_Done Jump to UpdateSaucerEntity_Done if it is not zero.
9D44 LD A,(IX+$1F) Read field 1F of the entity.
9D47 INC A Add one.
9D48 CP $09 Compare it with 09.
9D4A LD A,$00 Set the speed to 00.
9D4C LD (IX+$14),A Store the first byte of the speed in field 14 of the entity.
9D4F LD (IX+$15),A Store the second byte of the speed in field 15 of the entity.
9D52 JR Z,UpdateSaucerEntity_SetStep Jump to UpdateSaucerEntity_SetStep if field 1F was 08.
9D54 INC A Set the value to 01.
9D55 JR C,UpdateSaucerEntity_SetStep Jump to UpdateSaucerEntity_SetStep if field 1F was below 08.
9D57 NEG Set the value to FF.
UpdateSaucerEntity_SetStep 9D59 LD (IX+$12),A Store it in field 12 of the entity.
UpdateSaucerEntity_Done 9D5C LD (IX+$13),$00 Set field 13 of the entity to 00.
9D60 SET 7,(IX+$11) Set bit 7 of the heading of the entity.
9D64 JP UpdateEntity_Move Jump to UpdateEntity_Move to carry on updating the entity.
Prev: 9CA3 Up: Map Next: 9D67