![]() |
Routines |
| Prev: 40099 | Up: Map | Next: 40295 |
|
Updates an entity of the type 9 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 32 frames it fires a new entity of the type 14 from the position of this one, if there is a free entity to use.
|
||||||||
| UpdateSaucerEntity | 40122 | CALL IncreaseEntityCounter | Call IncreaseEntityCounter. | |||||
| 40125 | LD A,(41693) | Fetch the low byte of the frame counter from FrameCounter. | ||||||
| 40128 | RRA | Rotate bit 0 into the carry flag. | ||||||
| 40129 | CALL C,FacePlayer | Call FacePlayer on odd frames to choose the direction towards the player. | ||||||
| 40132 | LD B,2 | Set the size of the step to 2. | ||||||
| 40134 | CALL TurnEntity | Call TurnEntity to turn the entity towards the wanted heading. | ||||||
| 40137 | LD A,(24474) | Fetch the low byte of the seed from RandomNumber_Seed. | ||||||
| 40140 | AND %00011111 | Use bits 0-4. | ||||||
| 40142 | JR NZ,UpdateSaucerEntity_Speed | Jump to UpdateSaucerEntity_Speed unless they are all zero. | ||||||
| 40144 | PUSH IX | Copy the address of the entity into IY (using the stack). | ||||||
| 40146 | POP IY | |||||||
| 40148 | LD IX,46514 | Point IX at EntitiesEntity_03. | ||||||
| 40152 | LD B,2 | Look at 2 entities. | ||||||
| 40154 | CALL FindFreeEntity | Call FindFreeEntity to find a free entity. | ||||||
| 40157 | JR NZ,UpdateSaucerEntity_Speed | Jump to UpdateSaucerEntity_Speed if there is not one. | ||||||
| 40159 | CALL PlayShotSound | Call PlayShotSound. | ||||||
| 40162 | CALL ClearEntity | Call ClearEntity to clear the new entity. | ||||||
| 40165 | LD (IX+0),14 | Set the type of the new entity to 14. | ||||||
| 40169 | LD (IX+1),32 | Set the frame of the new entity to 32. | ||||||
| 40173 | LD BC,8 | BC is 8. | ||||||
| 40176 | LD H,(IY+2) | Fetch the first byte of the first coordinate of this entity. | ||||||
| 40179 | LD L,(IY+3) | Fetch the second byte of the first coordinate of this entity. | ||||||
| 40182 | ADD HL,BC | Add 8. | ||||||
| 40183 | LD (IX+2),H | Store the first byte of the first coordinate of the new entity. | ||||||
| 40186 | LD (IX+3),L | Store the second byte of the first coordinate of the new entity. | ||||||
| 40189 | LD H,(IY+5) | Fetch the first byte of the second coordinate of this entity. | ||||||
| 40192 | LD L,(IY+6) | Fetch the second byte of the second coordinate of this entity. | ||||||
| 40195 | ADD HL,BC | Add 8. | ||||||
| 40196 | LD (IX+5),H | Store the first byte of the second coordinate of the new entity. | ||||||
| 40199 | LD (IX+6),L | Store the second byte of the second coordinate of the new entity. | ||||||
| 40202 | LD C,3 | C is 3. | ||||||
| 40204 | LD H,(IY+8) | Fetch the first byte of the third coordinate of this entity. | ||||||
| 40207 | LD L,(IY+9) | Fetch the second byte of the third coordinate of this entity. | ||||||
| 40210 | LD (IX+8),H | Store the first byte of the third coordinate of the new entity. | ||||||
| 40213 | LD (IX+9),L | Store the second byte of the third coordinate of the new entity. | ||||||
| 40216 | LD (IX+11),4 | Set the first size of the new entity to 4. | ||||||
| 40220 | LD (IX+12),4 | Set the second size of the new entity to 4. | ||||||
| 40224 | LD (IX+13),4 | Set the third size of the new entity to 4. | ||||||
| 40228 | CALL SetUpShotSprite | Call SetUpShotSprite to set up the sprite of the new entity. | ||||||
| 40231 | LD A,(24474) | Fetch the low byte of the seed from RandomNumber_Seed. | ||||||
| 40234 | AND %00001111 | Use bits 0-3. | ||||||
| 40236 | LD (IX+32),A | Set field 32 of the new entity, the wanted heading. | ||||||
| 40239 | CALL FacePlayer | Call FacePlayer to choose the direction towards the player. | ||||||
| 40242 | LD A,(IX+32) | Read field 32 of the new entity. | ||||||
| 40245 | OR %10000000 | Set bit 7. | ||||||
| 40247 | LD (IX+17),A | Store it in field 17 of the new entity, the heading. | ||||||
| 40250 | PUSH IY | Copy the address of this entity back into IX (using the stack). | ||||||
| 40252 | POP IX | |||||||
| UpdateSaucerEntity_Speed | 40254 | LD A,(IX+18) | Read field 18 of the entity. | |||||
| 40257 | AND A | Test it. | ||||||
| 40258 | JR NZ,UpdateSaucerEntity_Done | Jump to UpdateSaucerEntity_Done if it is not zero. | ||||||
| 40260 | LD A,(IX+31) | Read field 31 of the entity. | ||||||
| 40263 | INC A | Add one. | ||||||
| 40264 | CP 9 | Compare it with 9. | ||||||
| 40266 | LD A,0 | Set the speed to 0. | ||||||
| 40268 | LD (IX+20),A | Store the first byte of the speed in field 20 of the entity. | ||||||
| 40271 | LD (IX+21),A | Store the second byte of the speed in field 21 of the entity. | ||||||
| 40274 | JR Z,UpdateSaucerEntity_SetStep | Jump to UpdateSaucerEntity_SetStep if field 31 was 8. | ||||||
| 40276 | INC A | Set the value to 1. | ||||||
| 40277 | JR C,UpdateSaucerEntity_SetStep | Jump to UpdateSaucerEntity_SetStep if field 31 was below 8. | ||||||
| 40279 | NEG | Set the value to 255. | ||||||
| UpdateSaucerEntity_SetStep | 40281 | LD (IX+18),A | Store it in field 18 of the entity. | |||||
| UpdateSaucerEntity_Done | 40284 | LD (IX+19),0 | Set field 19 of the entity to 0. | |||||
| 40288 | SET 7,(IX+17) | Set bit 7 of the heading of the entity. | ||||||
| 40292 | JP UpdateEntity_Move | Jump to UpdateEntity_Move to carry on updating the entity. | ||||||
| Prev: 40099 | Up: Map | Next: 40295 |