A* pathfinding on a 2D grid. More...
| Import Statement: | import Clayground.Algorithm |
GridPathfinder computes shortest paths on a 2D grid using the A* algorithm with a binary heap for efficient open-set management. Cells can be marked as walkable or blocked, and diagonal movement is optionally supported.
Example usage:
import Clayground.Algorithm GridPathfinder { id: pathfinder columns: 50 rows: 50 walkableData: myTileData diagonal: true } // Later: // var path = pathfinder.findPath(0, 0, 49, 49)
columns : int |
Number of columns in the grid.
diagonal : bool |
Allow diagonal movement (default: false).
rows : int |
Number of rows in the grid.
walkableData : var |
Flat array of grid cell values. 0 means walkable, 1+ means blocked.
The array is indexed as walkableData[y * columns + x]. When set, an internal copy is made so the original is not modified.
list findPath(int startX, int startY, int endX, int endY) |
Compute the shortest path between two grid cells using A*.
Returns an array of {x, y} objects from start to end (inclusive), or an empty array if no path exists.
void setWalkable(int x, int y, bool walkable) |
Set whether a single cell is walkable.