Prev: 26097 Up: Map Next: 26242
26103: Animate Explosion
Animates an explosion through three frames of a growing explosion (drawn in random colours) and then three frames to erase it again. At the end of the animation the object is restored to its old state (kept in IX+6), then:
  • if it is a bug, the object is removed;
  • if it was Robbie with an empty hand, the player's turn ends;
  • if it was Robbie carrying a can, the can is put back into a random empty cubby hole and then the player's turn ends.
Input
IX Explosion object
AnimateExplosion 26103 LD HL,24086 HL=CurrentBug_ID.
26106 INC (HL) Increment the bug counter by one.
26107 LD C,(IX+4) C=the animation frame from IX+4.
26110 LD B,(IX+5) B=the animation speed mask from IX+5.
26113 LD A,(24087) A=the game timer from GameTimer.
26116 AND B Keep only the bits set in the speed mask.
26117 JR NZ,ExplosionFetchSpriteFrame Jump to ExplosionFetchSpriteFrame if the result is not zero.
26119 INC (IX+4) Increment the animation frame by one.
ExplosionFetchSpriteFrame 26122 LD A,C A=the current explosion animation frame.
26123 SLA C Double the frame to make an offset into the table.
26125 LD B,0 Clear the high byte of the offset in B.
26127 LD HL,26242 HL=ExplosionLookupTable (the table of explosion sprites).
26130 ADD HL,BC Add the offset to find the sprite for the frame.
26131 LD E,(HL) DE=the sprite address for the frame from the table.
26132 INC HL
26133 LD D,(HL)
26134 LD L,(IX+1) L=the X position of the explosion.
26137 LD H,(IX+2) H=the Y position of the explosion.
26140 CP 6 If the current frame >= 6 then the animation has finished.
26142 JR NC,AnimateExplosion_End
26144 CP 3 If the current frame >= 3 then we are erasing it.
26146 JR NC,AnimateExplosion_Erase
26148 CALL DrawSprite Call DrawSprite.
26151 LD A,(24089) A=RandomNumber.
26154 AND %00000111 Keep only bits 0-2.
26156 OR %01000010 Set bits 1 and 6 (BRIGHT).
26158 LD (IX+3),A Write the random colour to IX+3 (the colour of the explosion).
26161 JP ColouriseSprite Jump to ColouriseSprite.
After an explosion, we check if it was the player that died!
AnimateExplosion_End 26164 LD A,(IX+6) Restore the old state of the object from IX+6.
26167 LD (IX+0),A
26170 CALL StoreEntity Call StoreEntity.
26173 CALL RemoveEntity Call RemoveEntity.
26176 LD (IX+0),0 Write 0 to IX+0 (make the object inactive).
26180 LD A,(IX+6) A=the old state.
26183 AND %00111111 Keep only bits 0-5.
26185 CP 3 Return if it was not Robbie (A >= 3).
26187 RET NC
26188 CP 2 Jump to PlayerTurnEnds if Robbie was not carrying a can (the type is not 2).
26190 JP NZ,PlayerTurnEnds
Robbie was carrying a can, so put it back in an empty cubby hole. A random hole is tried first, and then the following holes until an empty one is found.
26193 LD HL,24099 HL=CubbyHoles (the first cubby hole).
26196 LD BC,24109 BC=InactivePlayer_CubbyHoles (the end of the cubby holes).
26199 LD A,(24089) A=RandomNumber.
26202 AND %00000111 Keep only bits 0-2.
26204 LD E,A E=the random offset.
26205 LD D,0 Clear the high byte of the offset in D.
26207 ADD HL,DE Add the random offset to HL.
ExplosionCubbyHole_Loop 26208 LD A,(HL) A=the cubby hole.
26209 AND A Jump to ExplosionCubbyHole_Found if the hole is empty.
26210 JR Z,ExplosionCubbyHole_Found
26212 INC HL Move on to the next hole.
26213 PUSH HL Stash HL on the stack.
26214 AND A Compare HL with the end of the cubby holes.
26215 SBC HL,BC
26217 POP HL Restore HL from the stack.
26218 JR NZ,ExplosionCubbyHole_Loop Jump back to ExplosionCubbyHole_Loop if the end has not been reached.
26220 LD HL,24099 HL=CubbyHoles (wrap round to the first hole).
26223 JR ExplosionCubbyHole_Loop Jump to ExplosionCubbyHole_Loop.
ExplosionCubbyHole_Found 26225 LD A,(24183) A=the colour of the spray can from 24183.
26228 AND %00000111 Keep only bits 0-2.
26230 OR %00001000 Set bit 3 (the type of the item is a spray can).
26232 LD (HL),A Write the item to the cubby hole.
26233 JP PlayerTurnEnds Jump to PlayerTurnEnds.
Erase the explosion.
AnimateExplosion_Erase 26236 CALL SetUpPreviousSprite_Offset Call SetUpPreviousSprite_Offset.
26239 JP RemoveEntity_ClearNew Jump to RemoveEntity_ClearNew.
Prev: 26097 Up: Map Next: 26242