Prev: 36157 Up: Map Next: 36385
36162: Update Enemies
Used by the routines at RunLife and ExplodeShip.
Updates all nine enemy slots once a frame. The counter at 36691 tracks the explosion of the player's ship: it counts up from one when the ship is destroyed, the debris is started when it reaches ten, and the ship is gone for good when it has gone past that point.
UpdateEnemies 36162 LD A,(36691) Fetch the explosion counter from 36691.
36165 AND A Test it.
36166 JR Z,UpdateEnemies_Debris Jump to UpdateEnemies_Debris if the ship is intact.
36168 INC A Increase the counter...
36169 LD (36691),A ...and store it.
UpdateEnemies_Debris 36172 CP 10 Has the counter reached ten?
36174 CALL Z,ExplodePlayerShip Start the debris if so.
36177 LD A,(36691) Fetch the explosion counter again.
36180 CP 10 Is it ten or more?
36182 CALL NC,PlayExplosionSound Play the sound of the explosion if so.
36185 LD A,(23616) Fetch the value from Variables.
36188 LD (36017),A Store it in 36017.
36191 XOR A Clear A.
36192 LD (36395),A Clear the number of active enemies in 36395.
36195 LD (23616),A Clear Variables.
36198 LD A,(36156) Fetch the value from 36156.
36201 LD (36395),A Store it in 36395.
36204 LD IX,39284 Use the first enemy slot.
36208 LD B,9 Set the counter for nine slots.
UpdateEnemies_Loop 36210 PUSH BC Save the slot counter.
36211 PUSH IX Save the address of the slot.
36213 LD A,(IX+0) Fetch the type of the object in the slot.
36216 INC A Increment it.
36217 JP Z,UpdateEnemies_Skip Skip the slot if it is free.
36220 LD A,(IX+23) Fetch the second set of flags of the object.
36223 AND %11110000 Keep the top four bits.
36225 JR Z,UpdateEnemies_Exploding Jump to UpdateEnemies_Exploding if they are zero.
36227 SUB 16 Subtract one from the top four bits...
36229 LD B,A ...and store them back with the bottom four bits.
36230 LD A,(IX+23)
36233 AND 15
36235 OR B
36236 LD (IX+23),A
UpdateEnemies_Exploding 36239 LD A,(36691) Fetch the explosion counter from 36691.
36242 AND A Test it.
36243 JR Z,UpdateEnemies_Update Jump to UpdateEnemies_Update if the ship is intact.
36245 CP 4 Jump to UpdateEnemies_Update if the counter is four or higher.
36247 JR NC,UpdateEnemies_Update
36249 SET 3,(IX+23) Otherwise set bit 3 of the second set of flags.
UpdateEnemies_Update 36253 LD A,80 Set the collision effects in 36396 to 80.
36255 LD (36396),A
36258 LD A,(36395) Add one to the number of active enemies in 36395.
36261 INC A
36262 LD (36395),A
36265 CALL ResetSprites Reset the collision state.
36268 BIT 7,(IX+16) Test bit 7 of the flags.
36272 CALL NZ,CountActiveEnemy Call CountActiveEnemy if it is set.
36275 RES 6,(IX+16) Clear bit 6 of the flags.
36279 EXX Switch registers.
36280 CALL RunObjectHandler Run the code for the type of object.
36283 CALL ApplyCollisionEffects Deal with any collision at ApplyCollisionEffects.
36286 POP IX Restore the address of the slot.
36288 LD A,(IX+0) Fetch the type of the object.
36291 CP 19 Jump to UpdateEnemies_CheckHit if it is 19.
36293 JR Z,UpdateEnemies_CheckHit
36295 CP 28 Jump to UpdateEnemies_Type1C if it is 28.
36297 JR Z,UpdateEnemies_Type1C
36299 CP 29 Jump to UpdateEnemies_CheckHit if it is 29.
36301 JR Z,UpdateEnemies_CheckHit
36303 JR UpdateEnemies_Check Jump to UpdateEnemies_Check.
UpdateEnemies_Type1C 36305 LD A,(IX+20) Fetch the second state byte of the object.
36308 CP 2 Jump to UpdateEnemies_Check if it is two.
36310 JR Z,UpdateEnemies_Check
UpdateEnemies_CheckHit 36312 LD A,(41431) Fetch the flag from 41431.
36315 AND A Test it.
36316 JR Z,UpdateEnemies_Check Jump to UpdateEnemies_Check if it is clear.
36318 LD A,(41432) Fetch the flag from 41432.
36321 AND A Test it.
36322 JR NZ,UpdateEnemies_Check Jump to UpdateEnemies_Check if it is set.
36324 LD (IX+0),255 Otherwise free the slot.
UpdateEnemies_Check 36328 BIT 5,(IX+16) Jump to UpdateEnemies_Next if bit 5 of the flags is set.
36332 JR NZ,UpdateEnemies_Next
36334 BIT 3,(IX+23) Jump to UpdateEnemies_Next if bit 3 of the second set of flags is set.
36338 JR NZ,UpdateEnemies_Next
36340 CALL FindHitPosition Work out the position of a hit.
36343 CALL CheckShotCollisions Check for a collision with a shot.
This entry point is used by the routine at UpdateEnemies_Skip.
UpdateEnemies_Next 36346 LD BC,24 Set the length of a slot.
36349 ADD IX,BC Move on to the next slot.
36351 POP BC Restore the slot counter.
36352 DEC B Decrease the slot counter...
36353 JP NZ,UpdateEnemies_Loop ...and loop back to UpdateEnemies_Loop until none remain.
36356 LD A,(36395) Fetch the number of active enemies from 36395.
36359 CP 4 Return if there are four or more.
36361 RET NC Fetch a pseudo-random value from the refresh register.
36362 LD A,R Test bit 3.
36364 AND 8
36366 JR Z,UpdateEnemies_Spawn Jump to UpdateEnemies_Spawn if it is clear.
36368 LD A,(52824) Fetch the map zone from 52824.
36371 CP 11 Jump to UpdateEnemies_Spawn if it is 11 or more...
36373 JR NC,UpdateEnemies_Spawn
36375 CP 3 ...or less than 3.
36377 JR C,UpdateEnemies_Spawn
36379 JP SpawnSpecialEnemy Spawn a special enemy.
UpdateEnemies_Spawn 36382 JP UpdateEnemySpawning_Spawn Spawn an enemy.
Prev: 36157 Up: Map Next: 36385