Pathfinding is an integral part of many top-down games, especially RTS games like Starcraft or Age of Empires, in which you tell a unit where to go, and it figures out the best way to get there itself, navigating around obstacles and unwalkable spaces. A proven way of doing efficient and accurate pathfinding is using the A* search algorithm. After doing some tutorials on C++ and SDL, I thought I’d give it a shot. After getting some free-to-use art from http://opengameart.org/, I came up with the following:
The person and goal (the stairs) can obviously be replaced with anything in your game, such as a heat-seeking missile chasing a target or an enemy monster that comes after you, like Lust from The Binding of Isaac. Mixing pathfinding with other behaviors can quickly get game characters seeming alive and aware. A quick search will bring up resources on A* far better than I could put together in a short blog post, so I won’t go into details about how it works, but I will say that I think it’s a great exercise and a fun thought problem for beginning game developers to try to put together a demo implementing important mechanics like pathfinding. Putting this together has helped get game ideas boiling in my head, while simultaneously taking away the intimidation of making a full game.