本文整理汇总了Java中com.badlogic.gdx.ai.pfa.DefaultConnection类的典型用法代码示例。如果您正苦于以下问题:Java DefaultConnection类的具体用法?Java DefaultConnection怎么用?Java DefaultConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultConnection类属于com.badlogic.gdx.ai.pfa包,在下文中一共展示了DefaultConnection类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getConnections
点赞 3
import com.badlogic.gdx.ai.pfa.DefaultConnection; //导入依赖的package包/类
@Override
public Array<Connection<TileCoordinate>> getConnections(final TileCoordinate fromNode) {
Array<Connection<TileCoordinate>> array = new Array<>();
if (!isCollision(null, fromNode.getAbove())) {
array.add(new DefaultConnection<>(getCachedNode(fromNode), getCachedNode(fromNode.getAbove())));
}
if (!isCollision(null, fromNode.getBelow())) {
array.add(new DefaultConnection<>(getCachedNode(fromNode), getCachedNode(fromNode.getBelow())));
}
if (!isCollision(null, fromNode.getLeft())) {
array.add(new DefaultConnection<>(getCachedNode(fromNode), getCachedNode(fromNode.getLeft())));
}
if (!isCollision(null, fromNode.getRight())) {
array.add(new DefaultConnection<>(getCachedNode(fromNode), getCachedNode(fromNode.getRight())));
}
return array;
}
开发者ID:JayStGelais,
项目名称:jrpg-engine,
代码行数:19,
代码来源:GameMap.java
示例2: createGraph
点赞 2
import com.badlogic.gdx.ai.pfa.DefaultConnection; //导入依赖的package包/类
public static MyGraph createGraph (AStarMap map) {
final int height = map.getHeight();
final int width = map.getWidth();
MyGraph graph = new MyGraph(map);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
Node node = map.getNodeAt(x, y);
if (node.isWall) {
continue;
}
// Add a connection for each valid neighbor
for (int offset = 0; offset < NEIGHBORHOOD.length; offset++) {
int neighborX = node.x + NEIGHBORHOOD[offset][0];
int neighborY = node.y + NEIGHBORHOOD[offset][1];
if (neighborX >= 0 && neighborX < width && neighborY >= 0 && neighborY < height) {
Node neighbor = map.getNodeAt(neighborX, neighborY);
if (!neighbor.isWall) {
// Add connection to walkable neighbor
node.getConnections().add(new DefaultConnection<Node>(node, neighbor));
}
}
}
node.getConnections().shuffle();
}
}
return graph;
}
开发者ID:yichen0831,
项目名称:Pacman_libGdx,
代码行数:28,
代码来源:AStartPathFinding.java
示例3: generateGraph
点赞 2
import com.badlogic.gdx.ai.pfa.DefaultConnection; //导入依赖的package包/类
public static MyGraph generateGraph(TiledMapTileLayer mapCollisionLayer,int numCols,int numRows,int tileW,int tileH) {
final MyNode[][] nodes = new MyNode[numCols][numRows];
final Array<MyNode> indexedNodes = new Array<MyNode>(numCols * numRows);
//初始化数据地图
final String[][] tiles = new String[numCols][numRows];
for (int y = 0; y < numRows; y++) {
for (int x = 0; x < numCols; x++) {
tiles[x][y] = ".";
if(mapCollisionLayer!=null&&mapCollisionLayer.getCell(x, y)!=null){
tiles[x][y] = "#";
}
}
}
//print
if(Gdx.app.getLogLevel()==Application.LOG_DEBUG){
Gdx.app.debug(TAG,"----------------------------------");
StringBuilder temp = new StringBuilder("\n");
for (int y = 0; y < numRows; y++) {
for (int x = 0; x < numCols; x++) {
temp.append(tiles[x][numRows-1-y]) ;
}
temp.append("\n");
}
Gdx.app.debug(TAG,temp.toString());
Gdx.app.debug(TAG,"----------------------------------");
}
int index = 0;
for (int y = 0; y < numRows; y++) {
for (int x = 0; x < numCols; x++, index++) {
nodes[x][y] = new MyNode(index, x, y,tiles[x][y], 4);
indexedNodes.add(nodes[x][y]);
}
}
for (int y = 0; y < numRows; y++, index++) {
for (int x = 0; x < numCols; x++, index++) {
if (tiles[x][y].equals("#")) {
continue;
}
if (x - 1 >= 0 && tiles[x - 1][y].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x - 1][y]));
}
if (x + 1 < numCols && tiles[x + 1][y].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x + 1][y]));
}
if (y - 1 >= 0 && tiles[x][y - 1].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x][y - 1]));
}
if (y + 1 < numRows && tiles[x][y + 1].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x][y + 1]));
}
}
}
return new MyGraph(indexedNodes);
}
开发者ID:Mignet,
项目名称:Inspiration,
代码行数:62,
代码来源:GraphGenerator.java
示例4: createGraphFromTextRepresentation
点赞 2
import com.badlogic.gdx.ai.pfa.DefaultConnection; //导入依赖的package包/类
private static MyGraph createGraphFromTextRepresentation (final String graphTextRepresentation) {
final String[][] tiles = createStringTilesFromGraphTextRepresentation(graphTextRepresentation);
final int numRows = tiles[0].length;
final int numCols = tiles.length;
final MyNode[][] nodes = new MyNode[numCols][numRows];
final Array<MyNode> indexedNodes = new Array<MyNode>(numCols * numRows);
int index = 0;
for (int y = 0; y < numRows; y++) {
for (int x = 0; x < numCols; x++, index++) {
nodes[x][y] = new MyNode(index, x, y,tiles[x][y], 4);
indexedNodes.add(nodes[x][y]);
}
}
for (int y = 0; y < numRows; y++, index++) {
for (int x = 0; x < numCols; x++, index++) {
if (tiles[x][y].equals("#")) {
continue;
}
if (x - 1 >= 0 && tiles[x - 1][y].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x - 1][y]));
}
if (x + 1 < numCols && tiles[x + 1][y].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x + 1][y]));
}
if (y - 1 >= 0 && tiles[x][y - 1].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x][y - 1]));
}
if (y + 1 < numRows && tiles[x][y + 1].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x][y + 1]));
}
}
}
return new MyGraph(indexedNodes);
}
开发者ID:Mignet,
项目名称:Inspiration,
代码行数:45,
代码来源:GraphGenerator.java
示例5: createGraphFromTextRepresentation
点赞 2
import com.badlogic.gdx.ai.pfa.DefaultConnection; //导入依赖的package包/类
private static MyGraph createGraphFromTextRepresentation (final String graphTextRepresentation) {
final String[][] tiles = createStringTilesFromGraphTextRepresentation(graphTextRepresentation);
final int numRows = tiles[0].length;
final int numCols = tiles.length;
final MyNode[][] nodes = new MyNode[numCols][numRows];
final Array<MyNode> indexedNodes = new Array<>(numCols * numRows);
int index = 0;
for (int y = 0; y < numRows; y++) {
for (int x = 0; x < numCols; x++, index++) {
nodes[x][y] = new MyNode(index, x, y, 4);
indexedNodes.add(nodes[x][y]);
}
}
for (int y = 0; y < numRows; y++, index++) {
for (int x = 0; x < numCols; x++, index++) {
if (tiles[x][y].equals("#")) {
continue;
}
if (x - 1 >= 0 && tiles[x - 1][y].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x - 1][y]));
}
if (x + 1 < numCols && tiles[x + 1][y].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x + 1][y]));
}
if (y - 1 >= 0 && tiles[x][y - 1].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x][y - 1]));
}
if (y + 1 < numRows && tiles[x][y + 1].equals(".")) {
nodes[x][y].getConnections().add(new DefaultConnection<MyNode>(nodes[x][y], nodes[x][y + 1]));
}
}
}
return new MyGraph(indexedNodes);
}
开发者ID:Mignet,
项目名称:Inspiration,
代码行数:45,
代码来源:IndexedAStarPathFinderTest.java
示例6: addNeighbour
点赞 2
import com.badlogic.gdx.ai.pfa.DefaultConnection; //导入依赖的package包/类
public void addNeighbour(TestNode aNode) {
if (null != aNode) {
mConnections.add(new DefaultConnection<TestNode>(this, aNode));
}
}
开发者ID:chrizdekok,
项目名称:AStarPathFindingsSimpleExample,
代码行数:6,
代码来源:TestNode.java
示例7: addNeighbour
点赞 2
import com.badlogic.gdx.ai.pfa.DefaultConnection; //导入依赖的package包/类
public void addNeighbour(Node aNode) {
if (null != aNode) {
connections.add(new DefaultConnection<Node>(this, aNode));
}
}
开发者ID:Corosauce,
项目名称:AI_TestBed_v3,
代码行数:6,
代码来源:Node.java