Part 6 – Explosion animations

In this episode we will add the explosion animations for the Invaders. I did mention we’d add in the scoring as well but on reflection I’m going to leave that for a later episode because I do not want to put two different items in this article and scoring would be better suited when we have more game elements.

As usual the full code is below (expand and copy as required).

The length of an explosion
The amount of time the explosion graphic is on screen is determined by this constant:

The higher the number the longer the graphic remains on screen.

A new object status
An object’s status could be either ACTIVE or DESTROYED but now (if you look below) we have introduced a new status called EXPLODING

This code allows the UpdateDisplay routine to know when it should be displaying the explosion graphic for that object rather than its normal graphic.

The explosion graphic
The definition for the explosion starts at line 112 and will not be discussed further as graphics were covered in a earlier episode.

The Alien’s structure

We have added the variable to time how long the explosion remains on this screen for this Alien. Initially when it is hit it will be filled with the EXPLOSION_GFX_TIME constant value and then decremented for every time the code loops round its main loop. We’ll discuss this further shortly.

Missile Collisions
Previously within the routine MissileAndAlienCollisions we had a line that read

Alien[across][down].Ord.Status=DESTROYED;

Now (on line 288) we have changed this to

Alien[across][down].Ord.Status=EXPLODING;

To indicate that this Alien is exploding – not yet destroyed.

Displaying the explosions
In the UpdateDisplay routine we have added these lines at line 375

This code is executed if the Invader is not active (decided on line 354 – not shown here but in main code at the start of the article). Looking above we can see that if the Invader has the status of EXPLODING then we go on to decrement the explosion counter. Then we decide whether to display the explosion or mark the Invader as destroyed. If the explosion counter (ExplosionGfxCounter) is more than 0 we display the explosion else we mark the Invader as DESTROYED and then nothing else will happen for this Invader for this wave of Invaders.

Invader Initialisation
We need to add a couple of lines to the initialisation code:

Lines 411-412 are the new lines showing that we are setting the Invader Status to ACTIVE (this should have been included prior to this episode to be fair) and we also set the explosion counter to its starting point ready for an explosion to happen.

That’s it for now, next time we’ll look at adding the mothership that goes across the screen.

Enjoy and Learn 🙂