当前位置: 首页>>代码示例>>Java>>正文


Java IndexedAStarPathFinder类代码示例

本文整理汇总了Java中com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder的典型用法代码示例。如果您正苦于以下问题:Java IndexedAStarPathFinder类的具体用法?Java IndexedAStarPathFinder怎么用?Java IndexedAStarPathFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IndexedAStarPathFinder类属于com.badlogic.gdx.ai.pfa.indexed包,在下文中一共展示了IndexedAStarPathFinder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Pathway

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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<>();
}
 
开发者ID:conquest,项目名称:conquest,代码行数:10,代码来源:Pathway.java

示例2: PathFinder

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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());
        }
    };
}
 
开发者ID:JayStGelais,项目名称:jrpg-engine,代码行数:12,代码来源:PathFinder.java

示例3: main

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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));
			}
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:30,代码来源:GraphGenerator.java

示例4: create

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
@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();
}
 
开发者ID:chrizdekok,项目名称:AStarPathFindingsSimpleExample,代码行数:38,代码来源:Main.java

示例5: AStartPathFinding

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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);
        }
  };
}
 
开发者ID:yichen0831,项目名称:Pacman_libGdx,代码行数:13,代码来源:AStartPathFinding.java

示例6: NavMesh

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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();
}
 
开发者ID:jsjolund,项目名称:GdxDemo3D,代码行数:10,代码来源:NavMesh.java

示例7: resolveRouteJob

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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;
}
 
开发者ID:DaanVanYperen,项目名称:ns2-scc-profiler,代码行数:8,代码来源:RouteCalculationSystem.java

示例8: CalculatePreferredRoute

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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);
}
 
开发者ID:DaanVanYperen,项目名称:ns2-scc-profiler,代码行数:9,代码来源:PreferredRouteCalculationSystem.java

示例9: touchToMove

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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;
        }
    }
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:43,代码来源:WorldController.java

示例10: getPath

import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; //导入依赖的package包/类
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);
}
 
开发者ID:Corosauce,项目名称:AI_TestBed_v3,代码行数:43,代码来源:PathfinderHelper.java


注:本文中的com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。