Week 2 - Added working turrets


Well this week went much more smoothly than last, no painful oversights causing hours to go down the drain. So far I've gotten 4 turrets done, a working wave system, time until start countdown timer and working coin system for buying turrets.

The turrets so far have been interesting, the ballista was fairly straight forward, simply rotating to look at the enemy and firing a bolt every few seconds. The Ice Turret, or slowing turret, was also relatively simple, just a matter of adjusting the enemy movement speed when they entered the turret area of effect(AOE)/collider, then resetting once they leave the area. The final 2, the Slammer and the Lightning wer substatially more difficult to figure out. Both only deal damage within an area at intervals, enemies canm pass by unharmeds when the turrets aren't pulsing. The Slammer was a little easier than the lightning, I used a second sprite on the object that expanded across it's AOE using a Lerp to scale the sprite across a set duration time. This second sprite also has a collider attached to it that scales with it, meaning I was able to simply use collision physics to detect enemies and deal damage. 

The Lightning turret was more interesting as this is the first of the turrets to have animation involved. At first I used a loop within a coroutine to set the collider to active/inactive at set intervals. This method resulted in the collider and animation becoming very out of sync and enemies would be damaged and slowed when they shouldn't be. In the end, it turned out the solution was simply to get the animator state and enable/disable using the animator as a trigger.

The wave system over all, at least in it's current state, was extremely simple to implement. I only needed to track how many enemies to spawn based on wave number and how many enemies had been destroyed either by the player or by reaching the player's base. Once the destroyed enemies equalled the number to spawn that wave, run the next wave function, incrementing wave count and number of enemies to spawn.

The coin system was also relatively simple. Each turret has a set cost, the game then checks the variable for this cost against the current coins of the player and either buys and instantiates the turret, or flashes NOT ENOUGH COINS across the screen. The enemies simply have a value attached that adds to the players coins whenever they are destroyed. It has occured to me while typing this I will need to go through and ensure the player only earns coins when they destroy an enemy and not when the enemy reaches the player base.

The wave countdown timer was an insteresting one. Originally I had a loop within the spawner script that ran the count down in seconds, then a second script attached to the countdown text getting the current seconds count in an update function. Not only was this inefficient, it also only worked for the very first countdown. The between wave countdown was severely bugged and freaked out before disappearing and starting the wave anyway. To make this neater, with the advice of my tutor, i included everything in to the spawner script. In the end the issue was that I had an extra, unnecessary variable causing the countdown loop to be called numerous times at the end of the wave. Once removed, the counter worked perfectly and is all in the one place.

The target for next week is to have a variety of enemy types. Having them all increase health as the waves go one, as well as having faster but weaker ones, and tougher but slower ones. I'm also hoping to start on turret upgrades, increasing damage and fire rate or amount the enemy is slowed by. If everything goes smoothly, I may look in to a main menu, game over screen, highscore and maybe 1 other level.

Files

Tower_Defence_Build.zip Play in browser
Sep 16, 2021

Leave a comment

Log in with itch.io to leave a comment.