Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit/AppGameKit Studio Showcase / [WIP][TD] Janbo's Towerdefense

Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Jan 2022 18:59 Edited at: 24th Oct 2023 20:48
Janbo's Towerdenfense

Hello everyone,

this is my entry for the current comunity competition.
I not only want to showcase the Project but explain a bit about what i did, maybe some sources to learn the algorithm's and methods i used, so some of you might learn one or two things from it.

So let me begin with what i was aiming for because i knew from the start that i wanted to make a TD that was more like the open world equivalent to TD games, which are part of the classical TD's I think.
So when I think of TD's, i think of Mods/Maps for Warcraft 3 especially those where you can create a labyrinth for the enemys to walk through as i liked them the most as a kid and add more variety because everyone is doing it a bit different.

So i Just started by creating a project with some standard files like the main.agc, menu.agc, game.agc, input.agc and core.agc.
The reason why i started with those is because i also knew it'll become to big of a project to not seperate the code properly.
So In main there is nothing except of the stuff the AppGameKit wizzard creates for you and a call to the Init function for the menu which is inside the menu.agc ofc.
Then Creating a menu i use a finite state machine which translates pretty much to select case and looks like this for my case:

Here I hope you see how it is used and helps organizing the different menu branches, you also see that i use prefixs like "Menu_" and "Game_" which i use for all functions and variables that are meant to be used outide, kinda like the access level modifier "public" in other object orientated languages but also just to not run into a naming limit when i need multiple init functions for example as we don't have namespaces in AppGameKit Tier 1.
The core.agc which is a collection of functions i use often in my projects which I'm more than happy to share and most of them come from the comunity anyways:

The Game.agc is selfexplanatory i hope.

Now I dive directly into the level creation/generation cause my idea was to let the levels be generated differently for every single game session.
As the grapth to store the level i went for the easiest which is just a grid and pretty much translates to a 2D array where i can reference the different sprites/tiles, that way it will also be easy to work with later.
If you want to create a game with many sprites like i do/did i advise you to use atlas textures which you can load a single image using LoadSubImage()
To generate the map i knew i needed some sort of noise algorithm and we have a great comunity which already created a few noise librarys in the past and altered and trimed the code to my likings.

I also needed a way to dynamically select the single tiles frome the tile sheet/atlas texture which you can do with an auto tiling function maybe you can call it algorithm if you feel fancy but in the end you just do some bitmasking.
Here is the best website for tiling methods i could find on the Interwebz: cr31 Home

So loaded some media from Kenney's Free Assets used the noise library to generate a grid of empty and solid cells and placed the tiles using the 2-corner Wang Tile autotiling method.
This is how the autotiling looked like with a totally randomized level:

I used the perlin noise algorithm to tell my grid where to create solids/grass and where to create the path.
Then I added my flow field pathfinding library to work on the exact same 2D Array i use for the Tiles just with some additional attributes.

When I made my Library from like almost decades ago i used this website to learn from: Red Blob Games
The flow field pathfinding method is espacally usefull for this usecase as it doesnt need to calculate a path for every enemy but only once for every change in the graph and the enemys just follow the destination cell's stored in each cell of the grapth/grid/2DArray.
My library is also capable to calculate the path and distance to not only one destination but multiple destinations so it would allow for more complex levels after this competition

With the help of the pathfinding i could look for the enemy spawn positions, which i did by just iterating from all directions to the center of the level and just take the first cell that was reachable by the Pathfinder, but you can imagine all sorts of automated spawn placement methods with all those informations i have at this time.
And this is what it looked like after I made sure there is space around the destinations, added the enemy spawns, some foliage and added something i'd call vignette to the noise algorithm so it makes less and less path cells the further i reach the limit of the level until i just create a completely solid border around it:

After that the progression curve was pretty steep as i had the backbone ironed out already and could dive into enemy's and towers.
The Enemys, again all assets from Kenney, only needed to follow each cells destination cell with a smooth turn rate realized with the Core_CurveAngle() function from the core.agc

Now for the towers to aim and shoot at the enemys i had to get more creative as it is easy to tell that hundreds of towers and enemys checking for each other will be quite CPU demanding especally for the slow itteration speeds of AppGameKit Tier1.
So I had to come up with something that reduces the itterations from each tower to each enemy in range.

I tried manny things including Quadtrees but i setteled with partitioning the small cells into larger cells like minecraft has many blocks inside a chunck.
I made the Chunks larger than the maximum range of the towers so in the worst case the tower with the largest range only had to check for enemys inside 4 chunks.
Which i think is a good solution considereing i can make over 300 towers aim at over 1k Enemys at over 60 FPS ...on my PC and in Tier 1 atleast:

Then i added some graphical user interrfaces, infos and a digging feature as i had all the bacebone code for it in place and makes for a more interesting gameplay i think:

By now i have a Highscore list which is hosted on my Raspberry Pi i setup for this purpose only.
I installed Raspbian, apache, mariaDB, PHP and Adminer.
The updates to the Highscore are done using a set and get php script which looks like this:

The highscore list is only updated if you beat your own local record and can be watched in the game menu or via website

All images where taken at the day and time after i reached a milestone.
i still need to add some tutorual messages and options in the option menu.
Every tower and enemy attribute maybe even the level generation is still subject to change and Im more than happy if you make suggestions for all and everything.

Happy Testing !
I hope to see you on the highscore list
Janbo's Towerdefense on


Login to view attachments
Virtual Nomad
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 17th Jan 2022 21:49
janbo, my first test run ran flawlessly (~500FPS) and was quite fun (i only made it to a modest wave 33 ).

it has a nice old school TD vibe with the "labyrinth" approach and one that makes me want to play it again and again with the nearly-free form play.

the insight above is a priceless bonus and a big thanks for that!

finally, a reminder that all submissions are to be made via the jam page HERE; we'll be waiting

VIP Member
Gold Codemaster
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 25th Jan 2022 13:02 Edited at: 25th Jan 2022 13:02
I like your game.
As VN said with the random map it really motivates to play the game more often.

So, I like it.

Very good job.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 31st Jan 2022 11:04 Edited at: 31st Jan 2022 15:50

Also i screwed up a bit, cause i thought i had time until the end of this month so till today and i procrastinated so much so that i postponed it until, well the the deadline was reached yesterday.
I actually wanted to add a few tutorial speechbubles which show up the first time you play it, showing all the functions especially the info button cause i think this can be overseen quite easily.
And i wanted to add the spawns one by one so not all spawns are activated at the start allowing me to make the enemys harder, therefore have more endgame and it would make my game stand out from others a tiny bit again.
It's not really a problem for me, but still..

I want to add those changes but i don't know if i can just add them to my itchio page without changing the submission, cause that'd be cheating i guess.
Virtual Nomad
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 31st Jan 2022 17:26 Edited at: 31st Jan 2022 21:40
hey, janbo. it shouldn't allow you to change the files but you might be able to add text/images to the body. (just added "test" to my "template" which also doesn't allow changes to files, as expected)

otherwise, if it will help us enjoy playing, post whatever tutorial here

i was going to give your final version a run next but i'll wait in hopes that you do add the tuts/info.

couldn't wait and, frankly, what you've already got in the game makes sense. no need for a tutorial IMHO. now to climb the ladder
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Feb 2022 14:13 Edited at: 3rd Feb 2022 14:19
It's verry nice to see so many different names on my small highscore list.
@Virtual Nomad I will wait until the Competition ends for the people who actually want to play the game not just for the competition
And thanks to you and the mods for this competition i really enjoied it even if i procrastinated here and there

Login to post a reply

Server time is: 2024-02-24 21:44:51
Your offset time is: 2024-02-24 21:44:51