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


Java TileBasedMap类代码示例

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


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

示例1: build

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的package包/类
/**
 * Build a navigation mesh based on a tile map
 * 
 * @param map The map to build the navigation mesh from
 * @param tileBased True if we'll use the tiles for the mesh initially 
 * rather than quad spacing
 * @return The newly created navigation mesh 
 */
public NavMesh build(TileBasedMap map, boolean tileBased) {
	this.tileBased = tileBased;
	
	ArrayList spaces = new ArrayList();
	
	if (tileBased) {
		for (int x=0;x<map.getWidthInTiles();x++) {
			for (int y=0;y<map.getHeightInTiles();y++) {
				if (!map.blocked(this, x, y)) {
					spaces.add(new Space(x,y,1,1));
				}
			}
		}
	} else {
		Space space = new Space(0,0,map.getWidthInTiles(),map.getHeightInTiles());
	
		subsection(map, space, spaces);
	}
	
	while (mergeSpaces(spaces)) {}
	linkSpaces(spaces);
	
	return new NavMesh(spaces);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:33,代码来源:NavMeshBuilder.java

示例2: subsection

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的package包/类
/**
 * Subsection a space into smaller spaces if required to find a non-blocked
 * area.
 * 
 * @param map The map being processed
 * @param space The space being sections
 * @param spaces The list of spaces that have been created
 */
private void subsection(TileBasedMap map, Space space, ArrayList spaces) {
	if (!clear(map, space)) {
		float width2 = space.getWidth()/2;
		float height2 = space.getHeight()/2;
		
		if ((width2 < smallestSpace) && (height2 < smallestSpace)) {
			return;
		}
		
		subsection(map, new Space(space.getX(), space.getY(), width2, height2), spaces);
		subsection(map, new Space(space.getX(), space.getY()+height2, width2, height2), spaces);
		subsection(map, new Space(space.getX()+width2, space.getY(), width2, height2), spaces);
		subsection(map, new Space(space.getX()+width2, space.getY()+height2, width2, height2), spaces);
	} else {
		spaces.add(space);
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:26,代码来源:NavMeshBuilder.java

示例3: getCost

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的package包/类
/**
 * @see AStarHeuristic#getCost(TileBasedMap, Mover, int, int, int, int)
 */
public float getCost(TileBasedMap map, Mover mover, int x, int y, int tx, int ty) {		
	float dx = tx - x;
	float dy = ty - y;
	
	return ((dx*dx)+(dy*dy));
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:10,代码来源:ClosestSquaredHeuristic.java

示例4: getCost

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的package包/类
/**
 * @see AStarHeuristic#getCost(TileBasedMap, Mover, int, int, int, int)
 */
public float getCost(TileBasedMap map, Mover mover, int x, int y, int tx, int ty) {		
	float dx = tx - x;
	float dy = ty - y;
	
	float result = (float) (Math.sqrt((dx*dx)+(dy*dy)));
	
	return result;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:12,代码来源:ClosestHeuristic.java

示例5: clear

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的package包/类
/**
 * Check if a particular space is clear of blockages
 * 
 * @param map The map the spaces are being built from
 * @param space The space to check
 * @return True if there are no blockages in the space
 */
public boolean clear(TileBasedMap map, Space space) {
	if (tileBased) {
		return true;
	}
	
	float x = 0;
	boolean donex = false;
	
	while (x < space.getWidth()) {
		float y = 0;
		boolean doney = false;
		
		while (y < space.getHeight()) {
			sx = (int) (space.getX()+x);
			sy = (int) (space.getY()+y);
			
			if (map.blocked(this, sx, sy)) {
				return false;
			}
			
			y += 0.1f;
			if ((y > space.getHeight()) && (!doney)) {
				y = space.getHeight();
				doney = true;
			}
		}
		
		
		x += 0.1f;
		if ((x > space.getWidth()) && (!donex)) {
			x = space.getWidth();
			donex = true;
		}
	}
	
	return true;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:45,代码来源:NavMeshBuilder.java

示例6: getCost

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的package包/类
/**
 * @see AStarHeuristic#getCost(TileBasedMap, Mover, int, int, int, int)
 */
public float getCost(TileBasedMap map, Mover mover, int x, int y, int tx, int ty) {
    float dx = tx - x;
    float dy = ty - y;

    float result = (float) (Math.sqrt((dx*dx)+(dy*dy)));

    return result;
}
 
开发者ID:sciencectn,项目名称:SmartRover,代码行数:12,代码来源:ClosestHeuristic.java

示例7: getCost

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的package包/类
@Override
   public float getCost(TileBasedMap ctx, Mover mover, int x, int y,
    int goalX, int goalY) {
return Math.max(Math.abs(x - goalX), Math.abs(y - goalY));
/*
      float diagonal = Math.min(Math.abs(x - goalX), Math.abs(y - goalY));
      float straight = (Math.abs(x - goalX) + Math.abs(y - goalY));
      float h = (DIAGONAL_COST * diagonal) + (ADJACENT_COST * (straight - (2f * diagonal)));

      return h;*/
   }
 
开发者ID:Cr0s,项目名称:JavaRA,代码行数:12,代码来源:VehiclePathfinder.java

示例8: AbstractNpcController

import org.newdawn.slick.util.pathfinding.TileBasedMap; //导入依赖的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


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