Defense? Defence? I'll use the 's' version because America.
I was playing some Bloons TD6, with all the nostalgia as I hadn't played a tower defense in years. However, going further and further into the waves, my CPU started crying. Now, my computer isn't exactly top of the line, but so what? My laptop can run DOOM 2016, using integrated graphics, so what is Bloons doing that's taking up all that CPU time and memory.
Getting To Work
I decided the best way to find out is to make my own tower defense and try to make it as efficient as possible. Before I started, I had to make an aim. After not too long, I created a list.
- Storage on disk should not be over 512mb
- CPU should be under 10% (on my hardware, an R7)
- Memory should stay under 256mb (this should be way more than enough)
- Should be able to run 120TPS and 60FPS.
Seems pretty easy? And this is a hard limit. Realistically, the game should run at 1000TPS and 400FPS.
I had the idea, but I didn't have a name. After getting some ideas from ChatGPT, then disregarded it and chose Sentinels of the Void.
Starting the Project
I couldn't make a tower defense without a map to play with, so I need to make a map editor. This didn't need to be too hard, just a program that allowed me to play random lines in order. I then saved this to a file, and loaded it into the game. Now I just need the enemies to follow the path. This was my first issue. In a Plants Vs Zombies style TD, the enemies just walk in a straight line. But how do I make an enemy follow a path?
Here we show that we can use the dx
and dy
to find the angle. Using the angle we can get a way that an enemy can move, but what's even better about this is that we can multiply the new dx
and dy
by the enemy's speed so that each enemy can have its own movement.
When the enemy gets to the end of the line, we simply increment an index, and just do the same thing with the next line.
Seeing the Optimizations
As I'm working I can see so many optimization I can make, but regardless, the game is running well below the target limitations, so I don't need to implement them. I could pre-calculated all Sine and Cosine values, but it's not useful right now to my productivity. However, I will be taking mental notes of these optimizations in future when I do come across issues.
Another optimization that I will implement is pre-rendering some graphics. For example, text can be an expensive render, now it's not game haltingly bad, but it's obviously more expensive than a rectangle. Because of this, what I can do is pre-render text onto an image, and use that image instead. This will probably be my biggest graphical computation save especially at the start of production of the game.
Releasing the Game
Currently, V0.1 is out, and I'm close to finishing V0.2. The game has no art and at this point released with a map editor so that you can make your own levels for the game. I like adding modability to my games, so this is a small step towards that.
When I add art to the game I will do my best allow people to replace it with their own art, so they can change the game in any way they would like.
I would suggest trying out the game as it's only got a few minutes of gameplay. If you have any suggestions or feedback I would love to hear it. Lastly, I would love to head what you love most about Tower Defense games, because as much as I'm having fun making a game for efficiency, I also want it to be fun.
Top comments (0)