Bite Sized Game Development : Expanding Turret Defence

Attached Files

The following files have been attached to this tutorial:

.capx

Stats

1,271 visits, 1,914 views

Translations

This tutorial hasn't been translated.

Tools

In this tutorial, I will attempt to expand upon the 'Turret Defence' template that you can find in Construct 2. This will follow a similar structure to my Infinirunner tutorial, but should be slightly more advanced, and will build upon the game a bit more than in that tutorial. Because of all these additions, this tutorial is a little longer than my previous tutorials.

Part 1 : Adding more game 'rules'

Lets get started by giving the template game a few extra rules for play, a win state and a loss state are a good place to start, as is a restriction on the number of turrets the player can place.

We can add these quite easily. A win state can be when the player has survived a 'wave' of enemies, a loss state can be triggered by the player letting too many enemies through, and a restriction on the number of turrets the player can place can be done by implementing a 'resource' system, a finite number that the player uses up whenever a turret is placed. All of these things can be accomplished with a few global variables, and a few events that reference them. I've also added a few text boxes that update every tick to show the values of these new variables. We'll also need a few events that do things with these variables.

If you're unfamiliar with this kind of turret defence, the basic way this works is like this : A 'wave' is a set number of enemies spawning in the maze and should get harder over time, and the wave ends when all of these enemies have spawned and have been removed from the game area either because they made it to the end or because they were destroyed. Every enemy that makes it to the end of the maze costs the player a life, if they run out of lives, the player loses. Turrets cost resources to place, the player starts with enough resources to place a few early turrets, but must destroy enemies to gain additional resources. As the wave gets harder and more enemies spawn the player will be able to place more turrets to deal with the increased spawn rate or tougher enemies.

Once these variables and events are in place, you should end up with something like this :

https://dl.dropboxusercontent.com/u/245987915/Turret%20Defense/TD%20Waverules/index.html

Part 2 : Basic Powerups

Now we have proper win and loss states in the game, lets try adding something to make the game a little more exciting. Right now the only way to play is to place turrets and let them do the work. Lets add some powerups that the player can activate to assist them during the game. First we need some sprites for buttons that can be pressed to activate these powerups!

Im going to make two powerups to start off with, one of which will destroy all enemies on screen, and the other will double the fire rate of all the turrets on screen for a short time. Of course, when drawing the sprites, remember that each sprite should convey what the powerup actually does. Each sprite should also have a frame in its animation that you can switch to to indicate that the sprite is ready to be used.

These objects will need some instance variables in order to function correctly, and what variables they need is dependant on what they do. All powerup objects however will need a 'cooldown' variable, which will basically show us if each pwerup is ready to use or not, so lets make a powerups family and make the 'cooldown' variable common to all of them. The 'destroy all enemies' powerup for instance, will only need a 'cooldown' variable, because as it immediately eliminates all enemies on screen, the only thing we need to know when using it is if its ready or not. The 'double turret fire rate' powerup will need a few more variables added, because the player wants to activate it and have it run for a short amount of time, we need a boolean to tell wether it is active or not, and a timer to say when to turn it off after its been activated.

Now we have the buttons and variables, lets get our events made so that when the player touches or clicks on them, they activate. Theres a few little things to keep track of here, like keeping track of all the cooldowns of your powerups and insuring theres a way to show the player when they can be used, but the event group below shows one possible way of doing this :

I have added a few other things in this set of events, like an additional frame to the turret sprite to show when they are under the effect of the fire rate powerup. There is something else that is bothering me a little though. When we activate the powerups, we can tell when the powerup is ready, but we cant tell how long there is left on the cooldown. Lets fix that.

Im going to create two cooldown bars and use them as timers. We can do this quite simply by making the width or height of the bar equal to a percentage of the amount of cooldown left on the powerup that the bar is relating to. The events below can handle this method quickly and easily :

dl.dropboxusercontent.com/u/245987915/Screenshots/TD/TDPowerUpBars.png

Here is how the game plays with these powerups : dl.dropboxusercontent.com/u/245987915/Turret%20Defense/TD%20Powerups/index.html

There are many other kinds of powerups we can add, but these basic additions will do for now. Lets add some more dangerous enemies to use our new powers on!

Part 3 : New enemies, turrets and bosses

Part 3a : New enemies

The main way to make different types of enemies in a game like this is to simply vary certain variables they have. Theres many kinds of enemy we can make doing this, but for now we're going to focus on three kinds of enemies : Tougher, faster, and boss enemies. As you can probably gather, tougher enemies will take more shots to kill, faster enemies will move faster, and a boss enemy will simply absorb a massive amount of punishment before being destroyed.

To get set up for these new enemies, we should make a family for them so its easier to control them. This means we need to transfer all the behaviours we have for our one enemy and make them true for the whole family. This isnt difficult to do, just time consuming.

Clone the original enemy sprite and give it different colours for each enemy type, or if you're feeling artsy, give them different shapes entirely. We can then make the 4 different kinds of enemy we're going to have just be instances of this family with slightly different variables and behaviours. It should be easy enough to edit the behaviours of enemies to make them perform various tasks. Lets make the tougher enemies absorb twice as many hits, and make the faster enemies have double the movement speed. I will come to the boss enemy later.

Now lets get to how we spawn the enemies. We want these enemies to be 'elite' enemies that spawn less often than the normal enemy does. There are various ways we can accomplish this, but a good way is to have an 'elite' spawn every time a set number of normal enemies spawns, as this has the added side effect of keeping the original difficulty curve (which of course is a slowly increasing spawn rate of normal enemies). We can edit the spawn rate later to make balancing the difficulty level easier if we need to. Dont forget to add the totals to 'total enemies' so the game knows when they're all defeated!

Part 3b : New turrets

So we have some new elite enemies, lets make some new turrets in a similar way. Make a couple of new sprites and just like before, make a family of turrets so that we can manipulate their values easier, and incorporate the original turret into that family. Again, this might take some time, but is not particularly difficult to implement.

Once again, we can manipulate many things for turrets, for this example I have decided to make a turret that fires a slowly recharging long range laser that does massive damage, and a turret that adds a small area of effect to its attacks, otherwise known as splash damage.

These additions will be slightly harder than the enemy changes, for a few reasons. Firstly, we need a way to select these turrets before we place them. Secondly, both the laser and the splash damage effects will need new particle effects to be made to show when they fire, and finally, we need to find a way to add the mechanic of splash damage into the game.

Selection is a lot easier than it sounds. Give the buttons a boolean instance variable called 'Selected', and create three sprites that will serve as buttons. When one of these buttons is pressed, you set the 'selected' value to be true for the button that is pressed, and then when you place a turret, you place dependant on which button is selected. Just make sure you also have an indicator on the buttons to show which turret is selected. A good way is just to change the opacity of the buttons.

Now we can place all three types of turret lets do the fun part : Messing with their behaviour values! First, the laser turret. I'm going to massively increase its range, but also its refire rate. I want the laser turret to fire very slowly, but be able to take out an enemy in a single shot when it does fire. Dont forget to add a new sprite that can show this after you sort out the values. I have just created a long line sprite that fades immediately when fired :

As you can see, the laser has the unexpected side effect of destroying not just the first enemy it hits, but all of them the laser touches! This is actually pretty interesting, so im going to keep it in, but with three conditions : 1) That the fire rate is made even slower and the laser does not kill, but deals a large amount of damage 2) That the laser only damages enemies when its opacity is over 80 (i.e. almost immediately on firing) so that it doesnt destroy enemies during the end of it fading, and 3) that the resource cost of the laser turret is further increased to match its power. You may also want to tweak the targeting behaviours of the turret to give a better gameplay effect.

Now lets work on the last turret : the area of effect blast attack. This should be quite simple to do. Make the fire rate for this turret slower again. On firing, create a slow moving sprite that creates a medium sized circular sprite when it hits an enemy. Again, give the explosion sprite the fade property, and only have enemies under it take damage when the opacity is at 100. Tweak the amount of damage, refire rate and resource cost of the turret until it feels right and balanced.

With these changes to resource costs, it would be a good idea to place a few text objects near the buttons to show how much each turret costs. And dont forget to make sure the fire rate powerup also affects our two new turrets!

Now is the perfect time to playtest, playtest, playtest! As before you want to strike a good balance in regards difficulty so feel free to tweak any values you feel appropriate, such as enemy health/speed/number, turret damage/fire rate/resource cost, or changes to the resource system or powerups. There is no hard and fast rule for this sort of thing, you just have to go with what you feel is right. I've changed a lot of the numbers to suit my own feelings. Here is my game as it is now :

dl.dropboxusercontent.com/u/245987915/Turret%20Defense/TD%20Elites/index.html

Part 3c : The boss enemy

Now, the final test of the player's defences, the boss enemy! Make a new sprite in the enemies family, and make sure it is larger than the previous enemies. The boss enemy will mostly have the same behaviours as a normal enemy, but as its a boss enemy, it will be much much tougher to kill, a good estimate is around 100 times that of a normal enemy, and also much slower. We want to spawn the boss a short time after all the other enemies have spawned, and if the boss gets to the end, the player loses no matter how many lives they have.

With such a large amount of health, the boss really needs a little health bar to show the player how close it is to being destroyed. Create a bar sprite and use the every tick event to make display it wherever you feel appropriate. Similar to the powerup cooldown bars.

Once you have the boss spawning correctly and its health bar working, playtest a few times. Chances are, even with such a large amount of health the boss enemy is defeated quite easily. Lets allow the boss to spawn his own elites as he takes damage! You'll need a new global variable that ticks down whenever the boss takes damage (you will probably need to edit the events that handle damage for this), and has a value dependant on when you want the boss enemy to spawn minions. Whenever this value hits 0 or less, spawn the minions, return the value to its original number.

Even with these elites spawning once every while, the boss is quite easy to take down, and perhaps worse, is a little boring to kill. Alright, lets kick it up another notch. Add events to have the normal enemies spawning until the boss dies! You can choose wether to spawn these normal enemies from the boss or from the original spawn point, and wether you want everything to be destroyed when the boss dies or not. Again, playtesting to get whatever you feel is right is always the best option.

That's it for adding new enemies and turrets! Here is how my game currently plays :

dl.dropboxusercontent.com/u/245987915/Turret%20Defense/TD%20Boss/index.html

Part 4 : Additional layouts, menus and level designs

We could add more to the base game, but im going to move on to building a second level that the player can tackle. For this, we're going to want to build a whole new layout in construct 2. Dont worry if you havent used multiple layouts in C2 before, thats pretty simple in itself!

If you've never used more than one layout before, im going to quickly make a layout specifically for starting up the game menus and game instructions. In the projects window, right click 'layouts' and create a new layout called game menus, and give it a corresponding event sheet. You might want to use this moment to rename the current layout and its corresponding event sheet as well. You will want to make this layout the first layout in the project properties.

Add some text boxes to this new layout for titles. Then add buttons or text boxes to touch to take you to either the game or instructions. I have made a third which links to the tutorial as well. You either want the text in the boxes to change, or for new text boxes to appear when the right object is touched. Either way, you'll want a way to show the instructions, and a way to move to the first game layout. Im not going to add any more on this, because it should be fairly straight forward to set up a few text boxes to show the player how to play.

Now, lets move on to the layout for the second wave. Create a new layout. First, place the UI elements in, the text boxes and the buttons. Then, build the maze out of walls. This time, however, I am going to place a second routes through the maze, that uses a second spawn location and a second end zone. When you design the maze, it doesnt matter if one route is longer, but try to make sure both routes are at least of similar length and all the space is neatly used up, and dont forget to turn 'snap to grid' on in construct 2 as it will help greatly.

Go back to our original event sheet for the layout for wave 1, and copy all the events into a new event sheet for this layout. We could set the new layout to use Wave 1's event sheet, but we will want to make some changes, so for this example I have decided to just copy the whole thing so that we can edit it quite easily. There will be no need to copy the global variables, but we will edit some of our own in later.

Time to make some changes! For starters we're going to have to edit the 'On start of layout' event. The global variable values will still be active from the previous layout, so change them to what you want them to be at the start of this layout. I want this to be tougher, but the difficulty to scale up slowly. I am going to have this wave start slightly more resources for the player (dont forget we're facing double the enemies than before), more total enemies spawned, and a slower starting enemy spawn time.

Next up are the spawning events, we want to edit them so that when the spawn occurs we repeat the event for all of the enemy spawn locations. We then give the enemy spawned the value of the route they are going to take, and set their pathfinding location to the enemy target that has the same value as them. We also need to make sure the bosses (yes, thats right, two bosses!) spawn correctly and send their minions to the correct target spot. This sounds quite complicated but in reality is quite simple to achieve, it will just take a little time, just add some instance variables that hold the value of the route the enemies are taking through the maze, and make sure the right enemies match up to the right values. In addition, dont forget that when calculating how many enemies that are left, you have multiple spawn locations, so more enemies will spawn each time.

The only other things left to do are some minor changes here and there, to fix certain events now we have two sets of enemies. With all that done thats pretty much all you need to do to adapt this wave to a whole new maze. You know what comes next. Playtest, playtest, playtest and tweak difficulty levels until the game feels challenging but fair. Dont forget difficulty can be changed in many ways, for instance, remember that increasing the amount of enemies can make the boss fight easier, as it gives the player more resources to work with.

Part 5 : Third level

Alright, Lets make a final level, this level is going to be made up of a devastating initial seige against your forces coming from three different lanes, followed by three 'normal' bosses, and capped off with the final boss, the mothership. We're also going to add some other new toys into the mix. Create a new layout and new maze. Give the player a large amount of resources and the enemies a quick initial spawn time. We want this to be tough from the off. Give it a quick test to make sure it works.

I'm going to leave the design of the maze and the difficulty level up to you, and focus on the three main additions I want to make in this last wave : The mothership, a turret killer that eliminates a random turret once every while, and a new powerup to give the player a helping hand. However, im not going to go into specific detail on how to make these work, hopefully you should be able to work out the details by now.

The turret killer is actually quite easy to make. Every time the elites spawn, add to their event pick a random turret and destroy it. If you're feeling extra evil you could even make it pick two turrets. Make sure to add the explosion effect.

Next up is the new powerup. As with the original powerups, there are many variations you can make, but considering we've given the enemy a tool to destroy turrets, lets have a powerup that you can target that destroys a selection of enemies. You will need a new boolean for wether the touch activates the powerup or not, and new sprites for the explosion area of effect and the powerup button.

Now then, the mothership. Instead of the wave ending when all the bosses are destroyed we want this thing to spawn. Create a new sprite. Make sure its a big one. Give it the bullet property instead of the pathfinding property and enough health to match. We want it to (very) slowly move across the screen, shooting down turrets as it goes. We also want it to keep spawning lots of little minions as it goes to give the layer lots of resources to work with.

Spawn the mothership off the left side of the screen. It doesnt matter if your left most turrets start shooting at it before its visible. If the mothership manages to cross the screen and disappear off the right side, then the game is lost. You should be able to add this sprite and its behaviours in relatively quickly by now. You will also need a large enough health bar to match.

Heres a screenshot of my mothership wave and its little minions :

Once again, playtest the hell out of this last wave to make sure everything is working as you want it to work. In my version its meant to be very difficult, you might want to make it a little easier on the player than I have.

Part 6 : Further Touches

Alright, good stuff. We have a decent game here, allbeit with no sound and placeholder graphics. Lets add some minor touches to make the whole game feel better.

First things first, make sure your three layouts are linked together and all the transitions work correctly. On a loss or if the player defeats the mothership, the game should go back to the first layout. On a win, the game should move on to the next layout. Make sure that the layouts properly restart if the player loses and has to come back to a wave.

Next up are music and sound effects. the game is totally quiet right now, so a little aural stimulation would go a long way. The music in my game is 'Disco Ants go Clubbing' by Eric Matyas, at soundimage.org. I have not added any additional sound effects.

We could also add many more improvements to this game, such as nicer sprites and various UI improvements, flashing text when the bosses arrive but im going to leave it there for now.

Phew! We're done. That was a long one, you can find the final game here on the arcade : scirra.com/arcade/example/17560/td-expansion

.CAPX
  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!