Java 类com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder 实例源码

项目:conquest    文件:Pathway.java   
public Pathway(Array<Tile> tiles, Owner owner) {
    start = new Array<>();

    Map map = new Map(tiles.size, owner);
    pathFinder = new IndexedAStarPathFinder<>(map);
    heuristic = new EuclidianHeuristic();

    graphPath = new DefaultGraphPath<>();
}
项目:jrpg-engine    文件:PathFinder.java   
public PathFinder(final CachingIndexedGraph<TileCoordinate> graph) {
    this.graph = graph;
    pathFinder = new IndexedAStarPathFinder<TileCoordinate>(graph);
    heuristic = new Heuristic<TileCoordinate>() {

        @Override
        public float estimate(final TileCoordinate node, final TileCoordinate endNode) {
            return Math.abs(endNode.getX() - node.getX()) + Math.abs(endNode.getY() - node.getY());
        }
    };
}
项目:Inspiration    文件:GraphGenerator.java   
public static void main(String[] args) {
    // @off - disable libgdx formatter
            final String graphDrawing =
                ".....#....\n" +
                ".....#....\n" +
                ".....#....";
            // @on - enable libgdx formatter

            final MyGraph graph = createGraphFromTextRepresentation(graphDrawing);

            final IndexedAStarPathFinder<MyNode> pathfinder = new IndexedAStarPathFinder<MyNode>(graph);

            final GraphPath<MyNode> outPath = new DefaultGraphPath<MyNode>();

            // @off - disable libgdx formatter
            // 0123456789
            // S....#...E 0
            // .....#.... 10
            // .....#.... 20
            // @on - enable libgdx formatter
            final boolean searchResult = pathfinder.searchNodePath(graph.getNodes().get(0), graph.getNodes().get(20), new ManhattanDistance(),
                outPath);

            System.out.println(""+searchResult);
            System.out.println(""+outPath.getCount());
            for(int i=0;i<outPath.getCount();i++){
                System.out.println(""+outPath.get(i));
            }
}
项目:AStarPathFindingsSimpleExample    文件:Main.java   
@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]);
            }
        }
    }

    // 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();
}
项目:Pacman_libGdx    文件:AStartPathFinding.java   
public AStartPathFinding(AStarMap map) {
    this.map = map;
    this.pathfinder = new IndexedAStarPathFinder<Node>(createGraph(map));
    this.connectionPath = new DefaultGraphPath<Connection<Node>>();
    this.heuristic = new Heuristic<Node>() {
        @Override
        public float estimate (Node node, Node endNode) {
            // Manhattan distance
            return Math.abs(endNode.x - node.x) + Math.abs(endNode.y - node.y);
        }
  };
}
项目:GdxDemo3D    文件:NavMesh.java   
public NavMesh(Model model) {
    btTriangleIndexVertexArray vertexArray = new btTriangleIndexVertexArray(model.meshParts);
    collisionShape = new btBvhTriangleMeshShape(vertexArray, true);
    raycastCallback = new NavMeshRaycastCallback(navMeshRayFrom, navMeshRayTo);
    raycastCallback.setFlags(btTriangleRaycastCallback.EFlags.kF_FilterBackfaces);
    graph = new NavMeshGraph(model);
    pathFinder = new IndexedAStarPathFinder<Triangle>(graph);
    heuristic = new NavMeshHeuristic();
}
项目:ns2-scc-profiler    文件:RouteCalculationSystem.java   
public resolveRouteJob(IndexedAStarPathFinder<GridNode> finder, GridGraph graph, Entity a, Entity b, Team team) {
    this.finder = finder;
    this.graph = graph;
    this.a = a;
    this.b = b;
    this.team = team;
}
项目:ns2-scc-profiler    文件:PreferredRouteCalculationSystem.java   
public CalculatePreferredRoute(Team team, DefaultIndexedGraph<Routable> graph, Entity entityA, Entity entityB) {
    this.team = team;
    this.graph = graph;
    this.entityA = entityA;
    this.entityB = entityB;

    finder = new IndexedAStarPathFinder<>(graph);
}
项目:ns2-scc-profiler    文件:RouteCalculationSystem.java   
public resolveRouteJob(IndexedAStarPathFinder<GridNode> finder, GridGraph graph, Entity a, Entity b, Team team) {
    this.finder = finder;
    this.graph = graph;
    this.a = a;
    this.b = b;
    this.team = team;
}
项目:ns2-scc-profiler    文件:PreferredRouteCalculationSystem.java   
public CalculatePreferredRoute(Team team, DefaultIndexedGraph<Routable> graph, Entity entityA, Entity entityB) {
    this.team = team;
    this.graph = graph;
    this.entityA = entityA;
    this.entityB = entityB;

    finder = new IndexedAStarPathFinder<>(graph);
}
项目:Inspiration    文件:WorldController.java   
public void touchToMove(int screenX, int screenY) {
        Vector3 input = new Vector3(screenX, screenY, 0);
        camera.unproject(input);
        int x = MathUtils.floor(input.x / 32);
        int y = MathUtils.floor(input.y / 32);
        Gdx.app.debug(TAG, "clicked # (x:" + x + ",y:" + y + " )");
        //we click not npc or block,set aim to move
        if (!isCollisionWithNpc(x, y) && !isCollisionWithBlock(x, y)) {
            //A* path finding
            path.clear();
            Vector2 start = new Vector2(MathUtils.round(player.getX() / 32), MathUtils.round(player.getY() / 32));
            //we need set exactly start position
            Vector2 end = new Vector2(x, y);
            int numCols = mapMgr.cols;
            int numRows = mapMgr.rows;
            Gdx.app.debug(TAG, "From:" + start + " to " + end + "|numCols:" + numCols + "|numRows:" + numRows);
            int s = (int) start.x + ((int) start.y) * numCols;
            int t = (int) end.x + ((int) (end.y)) * numCols;
            List<Sprite> temp = new ArrayList<Sprite>();
            temp.addAll(mapMgr.npcs);
            temp.addAll(mapMgr.enemies);
//            temp.addAll(mapMgr.events);
            final MyGraph graph = GraphGenerator.generateGraph(mapMgr.getBlockLayer(), temp, numCols, numRows, 32, 32, start);
            final IndexedAStarPathFinder<MyNode> pathfinder = new IndexedAStarPathFinder<MyNode>(graph);
            final GraphPath<MyNode> outPath = new DefaultGraphPath<MyNode>();
            final boolean searchResult = pathfinder.searchNodePath(graph.getNodes().get(s), graph.getNodes().get(t), new ManhattanDistance(), outPath);
            MyPathSmoother pathSmoother = new MyPathSmoother(new MyRaycastCollisionDetector(graph));
            pathSmoother.smoothPath(outPath);
            StringBuilder sb = new StringBuilder();
            for (int i = outPath.getCount() - 1; i >= 0; i--) {
                sb.append("(" + outPath.get(i).getX() + "," + outPath.get(i).getY() + ")|");
                path.add(outPath.get(i));
            }
            if (searchResult) {
                Gdx.app.debug(TAG, "Start Follow Path:" + sb.toString());
                player.followPath(path);
                aim = new Aim(x, y);
            }
        } else {
            aim = null;
        }
    }
项目:AI_TestBed_v3    文件:PathfinderHelper.java   
public List<IntPair> getPath(int levelID, IntPair from, IntPair to) {



    graph = new Graph(128);
    path = new DefaultGraphPath<Node>();
    heuristic = new DistHeuristic();

    Level level = Game_AI_TestBed.instance().getLevel(levelID);


    nodes = new Node[level.getTileSizeX()][level.getTileSizeY()];

       int index = 0;
       for (int x = 0; x < level.getTileSizeX(); x++) {
           for (int y = 0; y < level.getTileSizeY(); y++) {
               if (level.isTilePassable(x, y)) {
                nodes[x][y] = new Node(x*Cst.TILESIZE,
                                               y*Cst.TILESIZE,
                                               index++);

                graph.addNode(nodes[x][y]);
               }
           }
       }

       for (int x = 0; x < nodes.length; x++) {
           for (int y = 0; y < nodes[0].length; y++) {
               if (null != nodes[x][y]) {
                   addNodeNeighbour(nodes, nodes[x][y], x - 1, y);
                   addNodeNeighbour(nodes, nodes[x][y], x + 1, y);
                   addNodeNeighbour(nodes, nodes[x][y], x, y - 1);
                   addNodeNeighbour(nodes, nodes[x][y], x, y + 1);
               }
           }
       }

    pathFinder = new IndexedAStarPathFinder<Node>(graph, true);


    return calcPath(from, to);
}