List of usage examples for com.badlogic.gdx.ai.pfa.indexed IndexedAStarPathFinder IndexedAStarPathFinder
@SuppressWarnings("unchecked") public IndexedAStarPathFinder(IndexedGraph<N> graph, boolean calculateMetrics)
From source file:com.hindelid.demo.pathfindingtest.Main.java
License:Apache License
@Override public void create() { mShapeRenderer = new ShapeRenderer(); mGraph = new TestGraph(20); mPath = new DefaultGraphPath<TestNode>(); mHeuristic = new ManhattanDistanceHeuristic(); // Initialize all the nodes that should be present. int index = 0; //Used to set index for every node. for (int x = 0; x < mMap.length; x++) { for (int y = 0; y < mMap[0].length; y++) { if (mMap[x][y] == 1) { mNodes[x][y] = new TestNode(x * TestNode.TILE_SIZE, y * TestNode.TILE_SIZE, index++); mGraph.addNode(mNodes[x][y]); }//w ww .j a v a 2 s. c om } } // Add connection to every neighbour of this node. for (int x = 0; x < mNodes.length; x++) { for (int y = 0; y < mNodes[0].length; y++) { if (null != mNodes[x][y]) { addNodeNeighbour(mNodes[x][y], x - 1, y); // Node to left addNodeNeighbour(mNodes[x][y], x + 1, y); // Node to right addNodeNeighbour(mNodes[x][y], x, y - 1); // Node below addNodeNeighbour(mNodes[x][y], x, y + 1); // Node above } } } mPathFinder = new IndexedAStarPathFinder<TestNode>(mGraph, true); calculatePath(); }