Example usage for com.badlogic.gdx.ai.pfa DefaultGraphPath DefaultGraphPath

List of usage examples for com.badlogic.gdx.ai.pfa DefaultGraphPath DefaultGraphPath

Introduction

In this page you can find the example usage for com.badlogic.gdx.ai.pfa DefaultGraphPath DefaultGraphPath.

Prototype

public DefaultGraphPath() 

Source Link

Document

Creates a DefaultGraphPath with no nodes.

Usage

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]);
            }/* www . ja  va2s .  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();
}

From source file:toniarts.openkeeper.world.WorldState.java

License:Open Source License

/**
 * FIXME: This can NOT be. Just for quick easy testing.
 *
 * @param start start point//from w ww.  j a  v a 2 s .  c om
 * @param end end point
 * @param creature the creature to find path for
 * @return output path, null if path not found
 */
public GraphPath<TileData> findPath(Point start, Point end, Creature creature) {
    pathFindingMap.setCreature(creature);
    GraphPath<TileData> outPath = new DefaultGraphPath<>();
    if (pathFinder.searchNodePath(getMapData().getTile(start.x, start.y), getMapData().getTile(end.x, end.y),
            heuristic, outPath)) {
        return outPath;
    }
    return null;
}

From source file:us.thirdmillenium.strategicassaultsimulator.agents.ConeAgent.java

License:Apache License

@Override
public void setPathToGoal(float goalX, float goalY) {
    // Reset Index Tracker
    this.preferredPathIndex = 0;

    // Start and Goal node
    TileNode startNode = GraphicsHelpers.findTileNodeByPixelLocation((int) this.position.x,
            (int) this.position.y, this.mapNodes);
    TileNode endNode = GraphicsHelpers.findTileNodeByPixelLocation((int) goalX, (int) goalY, this.mapNodes);

    // The returned path once computed
    this.preferredPath = new DefaultGraphPath<TileNode>();

    // Compute Path!
    this.pathFinder.searchNodePath(startNode, endNode, new TileHeuristic(), this.preferredPath);

    this.preferredPath.reverse();

    // Node Tracker
    Iterator<TileNode> itr = this.preferredPath.iterator();
    this.preferredPathNodeTracker = new HashSet<TileNode>(300);

    while (itr.hasNext()) {
        TileNode tile = itr.next();/* w  w  w . j a v  a2  s .com*/

        if (this.preferredPathNodeTracker.contains(tile)) {
            itr.remove();
        } else {
            this.preferredPathNodeTracker.add(tile);
        }
    }
}

From source file:us.thirdmillenium.strategicassaultsimulator.agents.PuppetAgent.java

License:Apache License

/**
 * Updates the Path to where you touch.//w w  w.  j a v  a2  s.  c o m
 * @param goalX
 * @param goalY
 */
@Override
public void setPathToGoal(float goalX, float goalY) {
    // Reset Index Tracker
    this.CurrentPathIndex = 1;

    // Start and Goal node
    TileNode startNode = GraphicsHelpers.findTileNodeByPixelLocation((int) this.position.x,
            (int) this.position.y, this.MapNodes);
    TileNode endNode = GraphicsHelpers.findTileNodeByPixelLocation((int) goalX, (int) goalY, this.MapNodes);

    // The returned path once computed
    this.CurrentPath = new DefaultGraphPath<TileNode>();

    // Compute Path!
    this.PathFinder.searchNodePath(startNode, endNode, new TileHeuristic(), this.CurrentPath);

    this.CurrentPath.reverse();

    // Node Tracker
    Iterator<TileNode> itr = CurrentPath.iterator();
    this.currPathNodeTracker = new HashSet<TileNode>(300);

    while (itr.hasNext()) {
        TileNode tile = itr.next();

        if (this.currPathNodeTracker.contains(tile)) {
            itr.remove();
        } else {
            this.currPathNodeTracker.add(tile);
        }
    }
}