Prev: 8D3D Up: Map Next: 8E21
8D42: Update Enemies
Used by the routines at RunLife and ExplodeShip.
Updates all nine enemy slots once a frame. The counter at 8F53 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 8D42 LD A,($8F53) Fetch the explosion counter from 8F53.
8D45 AND A Test it.
8D46 JR Z,UpdateEnemies_Debris Jump to UpdateEnemies_Debris if the ship is intact.
8D48 INC A Increase the counter...
8D49 LD ($8F53),A ...and store it.
UpdateEnemies_Debris 8D4C CP $0A Has the counter reached ten?
8D4E CALL Z,ExplodePlayerShip Start the debris if so.
8D51 LD A,($8F53) Fetch the explosion counter again.
8D54 CP $0A Is it ten or more?
8D56 CALL NC,PlayExplosionSound Play the sound of the explosion if so.
8D59 LD A,($5C40) Fetch the value from Variables.
8D5C LD ($8CB1),A Store it in 8CB1.
8D5F XOR A Clear A.
8D60 LD ($8E2B),A Clear the number of active enemies in 8E2B.
8D63 LD ($5C40),A Clear Variables.
8D66 LD A,($8D3C) Fetch the value from 8D3C.
8D69 LD ($8E2B),A Store it in 8E2B.
8D6C LD IX,$9974 Use the first enemy slot.
8D70 LD B,$09 Set the counter for nine slots.
UpdateEnemies_Loop 8D72 PUSH BC Save the slot counter.
8D73 PUSH IX Save the address of the slot.
8D75 LD A,(IX+$00) Fetch the type of the object in the slot.
8D78 INC A Increment it.
8D79 JP Z,UpdateEnemies_Skip Skip the slot if it is free.
8D7C LD A,(IX+$17) Fetch the second set of flags of the object.
8D7F AND %11110000 Keep the top four bits.
8D81 JR Z,UpdateEnemies_Exploding Jump to UpdateEnemies_Exploding if they are zero.
8D83 SUB $10 Subtract one from the top four bits...
8D85 LD B,A ...and store them back with the bottom four bits.
8D86 LD A,(IX+$17)
8D89 AND $0F
8D8B OR B
8D8C LD (IX+$17),A
UpdateEnemies_Exploding 8D8F LD A,($8F53) Fetch the explosion counter from 8F53.
8D92 AND A Test it.
8D93 JR Z,UpdateEnemies_Update Jump to UpdateEnemies_Update if the ship is intact.
8D95 CP $04 Jump to UpdateEnemies_Update if the counter is four or higher.
8D97 JR NC,UpdateEnemies_Update
8D99 SET 3,(IX+$17) Otherwise set bit 3 of the second set of flags.
UpdateEnemies_Update 8D9D LD A,$50 Set the collision effects in 8E2C to 50.
8D9F LD ($8E2C),A
8DA2 LD A,($8E2B) Add one to the number of active enemies in 8E2B.
8DA5 INC A
8DA6 LD ($8E2B),A
8DA9 CALL ResetSprites Reset the collision state.
8DAC BIT 7,(IX+$10) Test bit 7 of the flags.
8DB0 CALL NZ,CountActiveEnemy Call CountActiveEnemy if it is set.
8DB3 RES 6,(IX+$10) Clear bit 6 of the flags.
8DB7 EXX Switch registers.
8DB8 CALL RunObjectHandler Run the code for the type of object.
8DBB CALL ApplyCollisionEffects Deal with any collision at ApplyCollisionEffects.
8DBE POP IX Restore the address of the slot.
8DC0 LD A,(IX+$00) Fetch the type of the object.
8DC3 CP $13 Jump to UpdateEnemies_CheckHit if it is 13.
8DC5 JR Z,UpdateEnemies_CheckHit
8DC7 CP $1C Jump to UpdateEnemies_Type1C if it is 1C.
8DC9 JR Z,UpdateEnemies_Type1C
8DCB CP $1D Jump to UpdateEnemies_CheckHit if it is 1D.
8DCD JR Z,UpdateEnemies_CheckHit
8DCF JR UpdateEnemies_Check Jump to UpdateEnemies_Check.
UpdateEnemies_Type1C 8DD1 LD A,(IX+$14) Fetch the second state byte of the object.
8DD4 CP $02 Jump to UpdateEnemies_Check if it is two.
8DD6 JR Z,UpdateEnemies_Check
UpdateEnemies_CheckHit 8DD8 LD A,($A1D7) Fetch the flag from A1D7.
8DDB AND A Test it.
8DDC JR Z,UpdateEnemies_Check Jump to UpdateEnemies_Check if it is clear.
8DDE LD A,($A1D8) Fetch the flag from A1D8.
8DE1 AND A Test it.
8DE2 JR NZ,UpdateEnemies_Check Jump to UpdateEnemies_Check if it is set.
8DE4 LD (IX+$00),$FF Otherwise free the slot.
UpdateEnemies_Check 8DE8 BIT 5,(IX+$10) Jump to UpdateEnemies_Next if bit 5 of the flags is set.
8DEC JR NZ,UpdateEnemies_Next
8DEE BIT 3,(IX+$17) Jump to UpdateEnemies_Next if bit 3 of the second set of flags is set.
8DF2 JR NZ,UpdateEnemies_Next
8DF4 CALL FindHitPosition Work out the position of a hit.
8DF7 CALL CheckShotCollisions Check for a collision with a shot.
This entry point is used by the routine at UpdateEnemies_Skip.
UpdateEnemies_Next 8DFA LD BC,$0018 Set the length of a slot.
8DFD ADD IX,BC Move on to the next slot.
8DFF POP BC Restore the slot counter.
8E00 DEC B Decrease the slot counter...
8E01 JP NZ,UpdateEnemies_Loop ...and loop back to UpdateEnemies_Loop until none remain.
8E04 LD A,($8E2B) Fetch the number of active enemies from 8E2B.
8E07 CP $04 Return if there are four or more.
8E09 RET NC Fetch a pseudo-random value from the refresh register.
8E0A LD A,R Test bit 3.
8E0C AND $08
8E0E JR Z,UpdateEnemies_Spawn Jump to UpdateEnemies_Spawn if it is clear.
8E10 LD A,($CE58) Fetch the map zone from CE58.
8E13 CP $0B Jump to UpdateEnemies_Spawn if it is 0B or more...
8E15 JR NC,UpdateEnemies_Spawn
8E17 CP $03 ...or less than 03.
8E19 JR C,UpdateEnemies_Spawn
8E1B JP SpawnSpecialEnemy Spawn a special enemy.
UpdateEnemies_Spawn 8E1E JP UpdateEnemySpawning_Spawn Spawn an enemy.
Prev: 8D3D Up: Map Next: 8E21