As of today, we’re bring it all together – Today is the day that the tower defense game will start to really look as it should. Even thought this is an insanely interesting article, you really should read the other articles first – Most especially, How to build a tower defense flash game – Part 4 – Starting the tower attack!
In this article today we are going to do so many things:
- Creeps can now die
- We will make *WAVES of CREEPS* with different groupings and speeds
- We’ll add in some in game messaging
- Lastly, creatures that make it all the way around will attack again
Are you excited, well then lets get right into it. This is what we’ll have at the end of the tutorial:
Yeah, you’ll know how to make that at the end of this one article. Each creep has an increasing number of hit points after each wave, starting at 40 and going up to the final boss on wave 6 at 6000. Don’t worry I didn’t limit you with the burden of money yet, so you should have no problems. Just place as many towers as you need to get the job done!
Once again all the source code for this tutorial can be downloaded by clicking here.
Ok before we go over the code, lets first quickly overview what I added and where.
# In the instance of “Creep” > “CreepList” I added 5 additional frames of Enemy images in the “Creeps” layer
- We now have three new functions “kill”, leak and inGameMessage
- the function kill, removes the instance of the enemy and if it matches the number of kills for the wave it starts the next one
- the function leak, starts the enemy back at the first waypoint once it gets to the last one
- the function inGameMessage, records to the screen all text that calls it
- We added the “_root” variables “kills”, “creepLeaks”, “waves” and “wave”
- We added “health”, “maxhealth” and “isDead” as parameters to the enemies object.
- We also added “damage” to the projectile.
I know that looks like a lot, however, it makes logical sense – I swear. Basically what we are doing is giving the creeps health and a way to take that health away from them (the projectiles). Each time the projectile hits a given enemy it does a little bit of damage to it. Once the enemies health falls below zero, we remove the instance of it. To make this happen we add an additional parameter to the code in the “spawn” function such that when the creep is created we give it a certain amount of health. Where do we get this parameter to put things in? Good question, here it is
![]() |
This is where we customize our waves! It’s a pretty straight forward multi dimensional array. Right now we only concern ourselves with the number of attacking enemies, the health of them, the speed they travel at and the speed between releases.
It gives us the ability to do some pretty cool combinations. How about Groups – Set the release time to something small. How about fast enemies – set a high speed. You want to make a boss? Set the number to 1 and give it a ton of health. Done.
Now lets see how we put it all together.
Another important function that directly impacts how we handle the creeps. The “fire” function is called we now pass in an additional parameter that accounts for the damage that projectile will do.
The code in the fire function is just this
- r.damage = damage;
and later one in the “r” onEnterFrame, we do the check to see if we killed it with this shot – If we did we mark the “target enemy” as dead. The below code is placed right between the call to “Explosions” and the “this.removeMovieClip()” for the projectile.
this.targ.health = this.targ.health - this.damage;
if (targ.health <= 0)
{
targ.isDead = 1;
}
Once we have this code in the projectile, it’s a trivial matter to put the check in the onEnterFrame for the creep itself to see if it’s health has reached zero as I have done, or if isDead=1.
if (this.health <= 0)
{
_root.kill(this);
}
So now wen the projectile removes the damage from the creep and his health falls below zero the creep calls the kill function and we do the clean up.
![]() |
The kill function as describe above, simply removes the creep movie clip and increases the number of kills. We make an additional check to see if that total number of kills matches the number of kills required to finish the level. If this is the case, we call out “newLevel” function – A function we’ve used since the first tutorial.
![]() |
The leak function will be used later on to have the player take damage. Right now however, we use the function to update the position of the enemy and have them start back at the beginning of the waypoints.
![]() |
This is how we post text to the screen and give updates to the player – It’s currently a simple log windows that keeps the most active text history at the top. It is useful to give the player information about what is currently happening on the screen – What wave are we on? What type of creeps are attacking? etc. We’ll expand on this later as well.
![]() |
This code directly impacts the towers ability to enemy targets. We use the “” + creep == “” to determine if the creep that the tower that has targeted in fact is still alive. If it has already been destroyed we would catch it here and set our target to zero and pick another enemy target.
Ok, that’s it for another tutorial – We still have a lot to do! We still need to do upgrades, info, special towers, special creeps. So look forward to another tutorial soon.
How to build a tower defense flash game – Part 6 – Tower Powers!
You can click here to go back to the introduction






I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.
[...] you haven’t already read the last tutorial – How to build a tower defense flash game – Part 5 – Wave after Wave of Creep Kill’in! you should seriously consider giving it a [...]
[...] How to build a tower defense flash game – Part 5 – Wave after Wave of Creep Kill’in! [...]
[...] How to build a tower defense flash game – Part 5 – Wave after Wave of Creep Kill’in! [...]
love the site bookmark it for later