Tower Defender

Post Reply
jimbo
Posts: 12
Joined: Mon Oct 09, 2023 11:23 am

Tower Defender

Post by jimbo »

Tower Defender is the next game in my ongoing project to convert my various PET games over to X16. This ended up being more of a re-write given that the faster processor, sprite graphics, mouse controller, etc allowed for more enemies, more towers, a better UI, etc.

The goal of the game is to stop all of the "creeps" from exiting the playfield. You do this by building a maze using your sniper towers. You earn points for killing creeps, and spend those points to deploy more towers. As the game progresses your maze gets longer, and you even need to periodically change the maze to re-route creeps backwards through the maze to make sure your towers have enough shots at them.

For programmers, there are few things going on under the hood that you might be interested in:
- I coded a real-time path finding algorithm for the creeps so that they know the optimum path to exit. Their path changes as your maze gets more and more complicated. I use Djikstra's Algorithm, simplified to optimize for speed of calculating the best exit path during game play. It also calculates the distance to exit for each creep through the maze (used by the tower firing algorithms).
- I use a few different algorithms for the towers firing bullets and missiles:
-- When it is time for a bullet tower to fire, it chooses the creep that is closest to the exit, predicts where it will be in a second or so and uses the Symmetric Double Step Line Algorithm to fire straight at the predicted creep location.
-- Missiles use a simpler algorithm.. simply going up, down or diagonal towards the target creep until it hits it .. kind of like a guided missile I guess. When a missile hits its target creep it also damages any other creeps that might be nearby that creep (pythagorean theorem to find nearby creeps).

Screenshot 2024-02-17 at 8.25.04 AM.png
Screenshot 2024-02-17 at 8.25.04 AM.png (106.07 KiB) Viewed 373 times
A video playthrough of my highest score is here:
https://youtu.be/XVFoyagopzg

Download at:
twrdef.prg
(30 KiB) Downloaded 53 times
Try It Now!
Last edited by jimbo on Sat Feb 17, 2024 10:13 pm, edited 1 time in total.
mwiedmann
Posts: 67
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Re: Tower Defender

Post by mwiedmann »

This is really fun! Great work. There is a lot deeper strategy than I initially thought. Great design.
Post Reply