Saturday, February 15, 2014

Tower Defense: New enemy and spells!

So I made two big  additions since last time: added a new type of enemy and added spells.

I wanted to add a new enemy for a couple reasons... Previously the only way enemies were different or harder was their health was higher, and it could only go up so high since it's based on color values (the max was (255,255,255) which is white). If you put down a couple of white towers on the level, you were pretty much set and could kill everything no problem. So I wanted to add an enemy that would be a bit harder to kill, and act sort of like a boss. One thought was of splitting enemies... when you kill them, they split into smaller enemies. So right now I have splitting enemies that can split up to 2 times, and into however many enemies I want (it's just 2 right now). It's a lot more difficult to handle these things, since if you do kill them you now have even more enemies to kill.

I'm also trying to figure out a way to have high health enemies that aren't white, because right now there's no point in NOT getting a white tower. I want to have a red enemy that has as much health as a white enemy... this would incentivize having a high level red or magenta tower. As of right now my only ideas for this are adding enemies that have more than 255 as their color value, which would sort of act like a shield. So that's something to think about.

The next thing I added was spells. In a lot of tower defense games, players can use spells to interact/affect enemies without using towers and I wanted to add this to my game. My original idea was to have a paint brush effect that fades away and if enemies move over the paint, something happens. Unfortunately I couldn't really figure out how to produce a paintbrush effect and I think figuring out collision would be difficult. I ended up changing it slightly to be throwing paint onto the path. So right now there's three types of paints (three spells). There is red paint, which does damage to enemies that move over it, green paint that gives you money when enemies walk over it, and blue paint that slows enemies moving over it. I want to put these on a shared cooldown to make deciding which spell to use more important. So for instance if you want to thin out enemy numbers, you can use red paint or if you need more money to get the third upgrade for a tower you can use green paint. Maybe enemies are approaching a point in the path with lots of towers next to it so you can use blue paint so they take a lot of damage from the towers. I think it will make gameplay more interesting and more interactive.

Monday, February 10, 2014

Interface changes for adding/upgrading towers

So I was kind of unhappy with the interface of adding/upgrading towers, and I wanted to change it. First of all, you couldn't really see what the range of the tower was or how many upgrades it had or what it's damage was. So I added a feature where you can select towers, which does these things. It shows the attack radius of the tower, the towers stats appear in the upper right corner, and it shows upgrade paths. Every tower has three upgrade paths, a red, green, and a blue upgrade path. Taking an upgrade path is basically like combining your current tower with a red, green, or blue tower (depending on which path you take). I think it's good progress in the right direction, although I feel like I could make it more clear somehow.

The other big thing I did was add path indicators for enemies. Right now triangle appear pointing in the direction the enemy will take. This could be more clear too, but again I think it's a step in the right direction.

Here's a video detailing everything I just said!


Thursday, February 6, 2014

Upgrading towers, sounds, and classes in lua

So since the last post, I've added a few things to the tower defense game...

(1) I added menus! I actually got bored one day and wasn't sure what to do so I figured I'd get it out of the way. The main menu includes a campaign button that takes you through each level one after each other, a level selection button where you can choose just to play one level and then go back to the menu, and, of course, a quit button.

(2) Upgrading towers! Before, I just had three towers, and honestly it made gameplay kind of boring... there was no sense of "progression" or getting better. The way you upgrade a tower (as of now) is to just drag one tower onto another tower (with some extra cost) and it combines their damage. So if I combine a red and green I would now have a yellow tower (additive color model). Now this yellow tower can damage both red and green components. I also made it so when you upgrade a tower, it can target one more enemy (with the max being 3). As of now, you can upgrade towers to max level on every level, but I want to make it so you get another upgrade per level, so by the final levels you have all of them. This would give some sense of progression.

(3) Sounds... So I had an interesting idea for sounds. I've taken a few music theory courses, and I know some cool sounding chords. So my idea was to have each tower play a note when it attacks. When all the towers are attacking at once, you get this cool sounding chord. Right now I only have 4 notes for 4 towers (I need to put sounds in for 3 more towers). I still need to work on my execution of the sounds though (you can hear how it sounds in the video below)

(4) So another thing I did was to refactor my code a lot to use metatables (mimic classes). I found out about these things in lua called metatables. You can specify a metatable for a certain table and if you call a function that the table doesn't have, it will try to call the function with the metatable. For instance: say I have an Enemy table (enemy class) with an update and draw function in it. Now I want to make an "instance" of this Enemy, so I make a new table e to store the data, and set e's metatable to Enemy. Now I haven't set the function update or draw in e. So normally if I called e.draw or e.update there would be an error. Now that e has Enemy as a metatable, calling e.update is equivalent to calling Enemy.update and it's the same for A.draw. It makes the code a lot more readable, and actually uses less memory than the way I was doing it before (I'm not 100% positive about that). My reasoning for the memory is: Every time I was creating a new enemy, I would create a table with each function in it. So each enemy had it's own instance of the update function for instance. Now I just create one function in the metatable, and each instance calls that function. I'd imagine this reduces memory but I'm not sure.

Hope you found this interesting!