Follow goofballgames on Twitter

How to Build a Tower Defense Flash Game (Part 7 – Money and Upgrades!)

Posted by Goofball Games January - 31 - 2010 - Sunday

I’ve taken a much needed holiday vacation from my work, but I’m back to work at MTV and I’m all ready to get back into this. If this is the first time you’re viewing the page you may want to start at the beginning by clicking here) or you can see the previous part 6 if you just missed that one :^D

How to build a tower defense flash game – Part 6 – Tower Powers!

Anyway so you’ve read from the beginning lets get started! You can’t get something for nothing. That’s what my family always said, so why should tower defense games be any different. You need to make people work for it. That means you need to pay your towers for hire and the better the towers, the more they should cost. Don’t worry we won’t make anything too expensive, but keep in mind that this is “level balancing” and it is a hugely important step. If you give too much gold or make the towers too inexpensive then the game will be too easy, but if you make them cost too much people may not play your game long enough to buy them.

So you’ll find out that this specific tutorial we more about designing that complicated math or real programming – They’ll be plenty of programming, but nothing we can’t handle. It’s a tricky balance, that usually can only be helped by play testing – lots of play testing, but hey, it’s your game your making it’ll be fun.

Once again all the source code for this tutorial can be downloaded by clicking here

So you want to keep your gold pretty consistent across the board, you don’t want to give out different amounts of gold for each creep, it makes it hard for the user to make a plan with their tower strategy – What you usually see if a steady increase in the amount of gold given out on a per wave basis rise every 5 or 10 waves, starting at 1 or 2 gold with a wave comprising of about 10 or 20 creeps attacking at a time.

If you decide to have fewer (for say boss levels) then adjust your gold accordingly. You could even setup some form of equation based on hit-points of the creeps.

I will stick with the the trusty multiple of two golds for every 10 levels(ish). To make it interesting I usually give a boss level every 5th level and I give a a multiplier of 2.5 times. We’ll also give the play 80 to play around with as well. Obviously this is a general guide line not a strict rule.

So to recap the gold per level:

Level 1 – 5: 1 gold per creep

Level 6: Boss enemy of a specific type (25 gold)

Level 7 – 11: 1 gold per creep

Level 12: Another Boss… (50 gold)

Level 13 – 18: 2 gold per creep

and so on…

We can also give an interest rate for each level – You can make things interesting in the later levels forcing the user to decide between building a new tower and collecting interesting on the money saved.

Next we need to determine how much to charge for each tower. Well this is a little more specific, but it must be tied to the amount of money brought in. Don’t make a tower that cost so much you need to save 25 levels for it, because you still need to give it upgrades.

The above graphic labels where the upgrade window shows up when you click on a tower (Labeled as 1) and the info box that currently only lets the user know how much gold he has (Labeled as 2).

Starting at label 1. There is almost nothing hard to create here in terms of programming – We have a button “upgrade” that when clicked calls _root.upgrade(). That code is listed below:

The only thing that isn’t listed here is an multi-dim array within each of the towers. This multi-dim array just has enough information to upgrade “description”, “cost in gold”, “damage”, “range”, “rate”, “splash percentage”, “slow percentage”. Such as that listed below.

[“Damage: 40\rRange: 120\rSplash:No\rSlow:No”, 20, 40, 120, 5, 0, 0]

At the point in the above code – We have a tower selected and we just check to see if the gold the user has is enough to purchase the upgrade – if the player has the gold we upgrade the current tower levels to that of the new upgrade (we keep track of which upgrade we are on with the “level” variable). We then call “towerInfo” to display the now upgraded levels to the player and deduct the gold for that upgrade cost. Viola, you have a new upgrade tower – easy wasn’t it…

Lets quickly talk about “towerInfo”, this function was created before, but now we are using the function is not just draw the range of the tower anymore. Now we are going to display the upgrade information and the towers current level information.

If a tower is selected – then we display all the information we know about the tower – if no tower is selected then we show nothing. To sum this up, we you click on a tower make this information visible, otherwise don’t.

Right now this function is just for displaying “gold” levels for the player so he doesn’t have to guess how much gold he/she currently has. We are going to use it more when we want to give a score or have a “status” of what creeps might next be coming up .

Wow, we’ve done a lot of polish in this one – Not so much code was changed seriously, much more in design then anything else, but that’s ‘ok’ it means we are really making this into something special.

That’s it! We still have so much to do, but we’ve really hit a mile stone! You still can’t die, but it really feels like a complete game now.

How to build a tower defense flash game – Part 8 – Poison Tower and Basic Startup!

7 Responses to “How to Build a Tower Defense Flash Game (Part 7 – Money and Upgrades!)”

  1. [...] How to build a tower defense flash game – Part 7 – Gold and Upgrades! [...]

  2. [...] How to build a tower defense flash game – Part 7 – Gold and Upgrades! [...]

  3. [...] We are now at Part 8! You should be pretty up on your tower defense games at this point in the series. However, before we begin you should make sure you have reviewed the previous tutorials if you came here directly from a link. If this is the first time you’re viewing the page you may want to start at the beginning by clicking here or you can go to the previous tutorial Part 7 by clicking the below link: How to build a tower defense flash game – Part 7 – Gold and Upgrades! [...]

  4. derik says:

    thanks for the points , i will continue to follow your weblog

  5. ken clarke says:

    thanks for the tutorial, but i can’t make the gold calculate when i place a tower on the grass or kill a creep. I noticed you have a button on the place where the upgrade info is but i can’t see it, i just noticed the mouse pointer cursor changes to the hand cursor. Please how did you do it? i have even copied and pasted but still no result.

    If you can also show me how to make a “sell” request after the tower has been placed to remove the tower and replace the gold.

    thanks

  6. cole says:

    Interesting, i’ve been working on a tower defense game, most of the stuff i’ve done so far i’ve come up with on my own, but i’ve been stumped by the upgrade system for days now, it was either create a class representing the upgraded tower, set it’s location to the old tower, then remove the old tower from stage/delete references, or just upgrade the pre-existing towers stats. I tried the first but it’s been giving me so many problems… i guess i will just use this idea ^.^ thank you for the help

  7. kris says:

    It will also be GREAT if you can teach us how to make a “sell” button for the towers, i can’t remove the tower from screen. i tried the remove code in the main tower but it only made it remove all towers that represent it on screen when i clicked removed. As usual, i run to you. Keep up the GREAT work

Leave a Reply