libgdx/libgdx — pull request #1972 by baseball435 (2014-06-14 05:44:33+00:00)
Title: Pathfinding Implementation

Hello everyone. I have added a pathfinding system into Libgdx that can be used to get an Array of Nodes that will lead from a starting point to an ending point. This Array can then be used to walk through, draw, or whatever you want to do with it.

The important part about this implementation is that it is not bound directly with TileMaps and can be used anywhere. The way it works is when you first instantiate the PathFinder class you provide the width and height of the area that will be mapped out. You can also, optionally, provide a multidimensional array of boolean values which contains whether or not a node can be walked on at the given position of the array. So if at (5, 4) you don't want the node to be able to be walked on you would simply set array[5][4] = false.

Now of course this can be incorporated with TileMaps or your own map system. All you would have to do is give the width and height of the TileMap and then when providing the walkable array you would simply loop through each Tile and determine whether or not that Tile is able to be walked on. If it is you set the walkable array value at the given position to true otherwise you set it to false.

Here is a demonstration of the Pathfinding algorithm in action in my Game Engine: https://www.youtube.com/watch?v=5HW02maUCf8

And here is a demonstration of the Pathfinding algorithm being used in a game to walk entities across the path: https://www.youtube.com/watch?v=nDlPPHaMbKY

Please let me know what you think of the implementation!