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


Java AStarPathFinder类代码示例

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


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

示例1: testMoveRoverFromBottomLeftCornerToTopRightCorner

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public void testMoveRoverFromBottomLeftCornerToTopRightCorner() throws Exception {
    // Create a Finder with a large search distance (will never be reached)
    this.finder = new AStarPathFinder(map, 500, true);
    this.selectedx = 0;
    this.selectedy = 0;
    this.map.clearVisited();
    this.path = finder.findPath(new RoverMover(map.getUnit(selectedx, selectedy)), selectedx, selectedy, 2, 6);

    if (this.path != null) {
        for (int i = 0; i < this.path.getLength(); i++) {
            Log.i("test", "Current step " + this.path.getStep(i).getX() + ", " + this.path.getStep(i).getY());
        }
    } else {
        throw new AStarSearchTestCaseFailureException("Null path.");
    }
}
 
开发者ID:sciencectn,项目名称:SmartRover,代码行数:17,代码来源:LabTestsWithoutObstacles.java

示例2: Map

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public Map(String ref) throws SlickException {
	super(ref);
	
	// Start the Rectangles Array List
	tiles = new ArrayList<Tile>();
	
	// Setup blocked tiles
	blocked = new boolean[this.getWidth()][this.getHeight()];
	for(int i = 0; i < this.getWidth(); i++) {
		for(int j = 0; j < this.getHeight(); j++) {
			
			int tileID = getTileId(i, j, 1);
			String value = getTileProperty(tileID, "blocked", "false");
			if(value.equals("true")) {
				blocked[i][j] = true;
				tiles.add(new Tile((float)i * 16f, (float)j * 16f, 16f, 16f));
			}
		}
	}
	
	// PathFinding
	pathFinder = new AStarPathFinder(this, super.getWidth() * super.getHeight(), false);
}
 
开发者ID:lucas-tulio,项目名称:reddit-game-jam-5,代码行数:24,代码来源:Map.java

示例3: initWorld

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
private void initWorld(int w, int h) {
	floor = new boolean[w][h];
	walls = new boolean[w][h];
	item = new boolean[w][h];
	saw = new boolean[w][h];
	tiles = new Image[w][h];
	clear();
	Generator g = new Generator(w, h);
	g.generate(this);
	// set world limit
	setWidth(w * G.TILE_SIZE * 10);
	setHeight(h * G.TILE_SIZE * 10);

	// init gui
	gui = new Gui(this);
	// set camera
	camera = new Camera(this, G.playerEntity, container.getWidth(), container.getHeight(), 400, 400,
			new Vector2f(32, 32));
	camera.setFollow(G.playerEntity);
	G.world = this;
	pathFinder = new AStarPathFinder(this, 100, false);

	if (G.currentLevel == 1) {
		gui.addMessage("Welcome to CryptoRl 2 !");
	}

	alphaMap = ResourceManager.getImage("light");
}
 
开发者ID:Gornova,项目名称:CryptoRl2,代码行数:29,代码来源:GameWorld.java

示例4: Maze

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public Maze(int width, int height) throws SlickException {
	
	this.width = width;
	this.height = height;
	startingX = 1;
	startingY = 0;
	endingX = width - 3;
	endingY = height - 2;
	
	// Start the Rectangles Array List
	tiles = new ArrayList<Tile>();
	tileImage = new Image("/res/1x1.png");
	tileImage.setFilter(Image.FILTER_NEAREST);
	
	// Setup the Map
	blocked = new boolean[width][height];
	for(int i = 0; i < width; i++) {
		for(int j = 0; j < height; j++) {
			blocked[i][j] = true;
		}
	}
	
	// Starting and ending positions are not blocked!
	blocked[startingX][startingY] = false;
	blocked[endingX][endingY] = false;
	
	// PathFinding
	pathFinder = new AStarPathFinder(this, width * height, false);
	
	// Create the maze
	createMaze();
	
	// Create the Tiles
       refreshTiles();
}
 
开发者ID:lucas-tulio,项目名称:maze-generation-algorithms,代码行数:36,代码来源:Maze.java

示例5: AbstractNpcController

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
/**
 * Create a new npc controller.
 * 
 * @param gameController
 *            The GameController to be used.
 * @param model
 *            The model that this controller should control.
 * @param map
 *            The tile based map to be used.
 */
AbstractNpcController(GameController gameController,
		AbstractNpcModel model, TileBasedMap map) {
	super(gameController);
	this.setPathFinder(new AStarPathFinder(map, 500, true));
	this.setModel(model);
	this.setView(new CharacterView(model));
	this.setDefaultTiles(model.getMinTileX(), model.getMaxTileX(),
			model.getMinTileY(), model.getMaxTileY());
	this.pauseTime = 0;
}
 
开发者ID:verath,项目名称:ESCP,代码行数:21,代码来源:AbstractNpcController.java

示例6: Pathfinder

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public Pathfinder(Person p) {        
    this.p = p;
    pmap = new BooleanPathfindingMap(p, 10);//perception of 10, the person can see 10 positions ahead to detect mobile obstacles
    pathfinder = new AStarPathFinder(pmap, 10000, true);//plan with no more than 1000 steps,diagonal movement allowed        
    Logger.getLogger(Pathfinder.class.getName()).setLevel(Level.WARNING);//change to info for more details about pathfinding

}
 
开发者ID:emilioserra,项目名称:UbikSim,代码行数:8,代码来源:Pathfinder.java

示例7: Map

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
/**
 * Creates the map. Reads from Tiled and sets an offset according to the camera
 * @param ref
 * @param tileSetsLocation
 * @param xOffset
 * @param yOffset
 * @throws SlickException
 */
public Map(String ref, String tileSetsLocation, int xOffset, int yOffset) throws SlickException {
	
	// Starts the base Map
	super(ref, tileSetsLocation);
	
	// Defines the X and Y render positions
	this.xOffset = xOffset;
	this.yOffset = yOffset;
			
	// Creates the Blocked and Playable Tiles
	blocked = new boolean[getWidth()][getHeight()];
	playable = new boolean[getWidth()][getHeight()];
	
	walls = new ArrayList<Wall>();
	floors = new ArrayList<Floor>();
	
	// Creates the Game Tiles
	gameTiles = new GameTile[getWidth()][getHeight()];
	
	// Spawn point
	spawnPoint = new Tile(13, 13);
	
	// These attributes store the tiles the user is pointing at
	xTileAtMouse = 0;
	yTileAtMouse = 0;
	
	// PathFinding
	pathFinder = new AStarPathFinder(this, super.getWidth() * super.getHeight(), false);

	// This will create the map, unblock/block the Tiles and set the polygon Shapes for every Tile
	for (int xTile = 0; xTile < getWidth(); xTile++) {
		for(int yTile = 0; yTile < getHeight(); yTile++) {
			
			// Read the Tilemap File for Playable Tiles
			String playableValue = getTileProperty(getTileId(xTile, yTile, FLOOR), "playable", "false");
			playable[xTile][yTile] = playableValue.equals("true");

			// Blocked?
			blocked[xTile][yTile] = !playable[xTile][yTile];
			
			// Defines the xi and yi relative positions of each polygon
			float tileXPos = (tileWidth / 2 * xTile) - (tileWidth / 2 * yTile);
			float tileYPos = (tileHeight / 2 * xTile) + (tileHeight / 2 * yTile);
			
			// Math to form the polygon
			gameTiles[xTile][yTile] = new GameTile(
					
				// Isometric rendering
				tileXPos, tileYPos + tileHeight / 2,				// x0, y0
				tileXPos + tileWidth / 2, tileYPos,					// x1, y1
				tileXPos + tileWidth, tileYPos + tileHeight / 2,	// x2, y2
				tileXPos + tileWidth / 2, tileYPos + tileHeight);	// x3, y3
		}
	}
	
	// Generate the Map walls and floor
	updateMapLimits();
}
 
开发者ID:lucas-tulio,项目名称:awesome-game-store,代码行数:67,代码来源:Map.java

示例8: VehiclePathfinder

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public VehiclePathfinder(World world) {
this.pathfinder = new AStarPathFinder(world, MAX_SEARCH_DISTANCE,
	true, new ClosestHeuristic());
   }
 
开发者ID:Cr0s,项目名称:JavaRA,代码行数:5,代码来源:VehiclePathfinder.java

示例9: InfantryPathfinder

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public InfantryPathfinder(World world) {
this.pathfinder = new AStarPathFinder(world, MAX_SEARCH_DISTANCE,
	true, new ClosestHeuristic());
   }
 
开发者ID:Cr0s,项目名称:JavaRA,代码行数:5,代码来源:InfantryPathfinder.java

示例10: getPathFinder

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public AStarPathFinder getPathFinder() {
	return pathFinder;
}
 
开发者ID:lucas-tulio,项目名称:maze-generation-algorithms,代码行数:4,代码来源:Maze.java

示例11: setPathFinder

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public void setPathFinder(AStarPathFinder pathFinder) {
	this.pathFinder = pathFinder;
}
 
开发者ID:lucas-tulio,项目名称:maze-generation-algorithms,代码行数:4,代码来源:Maze.java

示例12: main

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public static void main(String[] args) {

        SimpleMap map = new SimpleMap();

        /** documentation at: http://slick.ninjacave.com/javadoc/org/newdawn/slick/util/pathfinding/AStarPathFinder.html */
        AStarPathFinder pathFinder = new AStarPathFinder(map, MAX_PATH_LENGTH, false);
        Path path = pathFinder.findPath(null, START_X, START_Y, GOAL_X, GOAL_Y);

        int length = path.getLength();
        System.out.println("Found path of length: " + length + ".");

        for(int i = 0; i < length; i++) {
            System.out.println("Move to: " + path.getX(i) + "," + path.getY(i) + ".");
        }

    }
 
开发者ID:emilioserra,项目名称:UbikSim,代码行数:17,代码来源:PathfinderDemo.java

示例13: PathfinderChecker

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
public PathfinderChecker(String pathScenario) {
    Ubik u= new Ubik(1);        
    u.setPathScenario(pathScenario);      
    u.init();
   
    String s= "Scenario checked: " + pathScenario + "\n";
    int np= (u.getBuilding().getFloor(0).getPersonHandler().getPersons()).size();
    if(np==0) {
        s+="Add some person for a thorough inform \n";
        return;
    }
    s+= "Persons included: " + np + "\n";
    
    Person p=(u.getBuilding().getFloor(0).getPersonHandler().getPersons()).get(0);
    
    List<Room> lr= PositionTools.getRooms(p);
    s+= "List of Rooms included: \n";
    for(Room r: lr){
        s+="\t" + r.getName()+ "\n";
    }
    

    BooleanPathfindingMap pmap = new BooleanPathfindingMap(p, 10);//perception of 10, the person can see 10 positions ahead to detect mobile obstacles
    AStarPathFinder pathfinder = new AStarPathFinder(pmap, maxSteps, true);//plan with no more than 1000 steps,diagonal movement allowed  
    List<String> nrr=new ArrayList<String>(); //non reachable rooms
    for(Room r1: lr){
        for(Room r2:lr){
            if(lr.indexOf(r1)<lr.indexOf(r2)){//if r1 reaches r2, r2 also reaches r1
                //check reachability                        
                Path path = pathfinder.findPath(null, r1.getCenter().x, r1.getCenter().y, r2.getCenter().x, r2.getCenter().y); //get path 
                LOG.info("Reachability " + r1.getName() +  " to " + r2.getName() +  " checked");
                if(path==null) nrr.add(r1.getName() + " <-> " + r2.getName());
            }
        }
    }
    if(nrr.isEmpty()) s+="All rooms are reachable!";                    
    else{
        s+= "Not reachable rooms with  " + maxSteps + " steps: \n";
        for(String nonreachable: nrr){
            s+="\t" + nonreachable + "\n";
        }
    }
    inform=s;
    
    
    
    
}
 
开发者ID:emilioserra,项目名称:UbikSim,代码行数:49,代码来源:PathfinderChecker.java

示例14: setPathFinder

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
/**
 * Set path finder
 * 
 * @param pathFinder
 *            the pathfinder to use
 */
void setPathFinder(AStarPathFinder pathFinder) {
	this.myPathFinder = pathFinder;
}
 
开发者ID:verath,项目名称:ESCP,代码行数:10,代码来源:AbstractNpcController.java

示例15: getPathFinder

import org.newdawn.slick.util.pathfinding.AStarPathFinder; //导入依赖的package包/类
/**
 * get current pathfinder
 * 
 * @return the active pathfinder
 */
AStarPathFinder getPathFinder() {
	return myPathFinder;
}
 
开发者ID:verath,项目名称:ESCP,代码行数:9,代码来源:AbstractNpcController.java


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