Howdy y’all! Here is a demo of the pathfinding for my upcoming game currently called Project Ascent! I’ve spent about two weeks working out this pathfinding and putting together this demo for you all to try out. It uses the A* algorithm to calculate an open path between the teal space at the bottom left and the teal space at the top right. You can find the demo here.
When you first open the demo, you’ll be greeted with this grid:
The teal spaces are your start and end points, the darker turquoise tiles show the path the algorithm has found to get from one to the other. The numbers simply show the order in which the algorithm checked tiles while it was searching for the best path forward.
However, as it is, this doesn’t exactly seem like the greatest pathfinding challenge around. Here’s where the fun begins: Try clicking on any of the numbered spaces, and you should see something like this:
You can place purple barriers! Make any pattern you like, and then click on the bottom left square to have the algorithm calculate a new path, and …
Voila!
You now know how to get from point A to point B around all your obstacles!
Two quick warnings before you jump too far in:
- The algorithm only checks tiles which are horizontally and vertically adjacent, so it can’t navigate through two barriers that meet at a corner.
- If you completely block the algorithm’s path, it simply won’t do anything. So if you’re not getting any results, double check that there’s actually a way to the end.
Now, this is fun for a minute or two to play around with, but it’s not exactly the most engaging game around. However, it’s an integral component to Project Ascent, the music-driven tower defence game I’m working on for my Creative Computing capstone. This algorithm will allow enemies to navigate the battlefield and react dynamically to obstacles you put in their way! It’s a long way from being done, but this is the first big step. Stick around here, and I’ll keep you up to date on all the latest progress on the game. Once I have some early playable versions, I’ll chuck them up here as well, so you all can try them out!
______________________________________________________________________________
If you want to learn more about how the A* algorithm works and how it can include diagonals, I recommend Sebastian Lague’s video on the subject here.
Oh, and if you find any other issues with the program, or have any suggestions or comments, please let me know on my twitter @theAdeptYeti.