auto-link tiles
This commit is contained in:
@@ -52,12 +52,32 @@ public class GameMap {
|
||||
public void dig(Vector2 worldCoord) {
|
||||
Vector2 coord = tileMap.toTileMapCoord(worldCoord);
|
||||
|
||||
tileMap.setTile(13, (int) coord.x, (int) coord.y);
|
||||
|
||||
for (int i = -1; i < 2; i ++) {
|
||||
for (int j = -1; j < 2; j ++) {
|
||||
Tile tile = tileMap.getTile( (int) coord.x + j, (int) coord.y + i);
|
||||
if (!dirtTiles.contains(tile.getId())) {
|
||||
int tileType = getTileType((int) coord.x + j, (int) coord.y + i);
|
||||
int tileId = tileTypeToId(tileType);
|
||||
|
||||
tileMap.setTile(tileId, (int) coord.x + j, (int) coord.y + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void render(SpriteBatch spriteBatch) {
|
||||
this.tileMap.render(spriteBatch);
|
||||
}
|
||||
|
||||
private int getTileType(int coordX, int coordY) {
|
||||
// count tiles around
|
||||
int p = 0;
|
||||
int tileType = 0;
|
||||
for (int i = -1; i < 2; i ++) {
|
||||
for (int j = -1; j < 2; j ++) {
|
||||
Tile tile = tileMap.getTile((int) coord.x + j, (int) coord.y + i);
|
||||
Tile tile = tileMap.getTile( coordX + j, coordY + i);
|
||||
|
||||
if (!dirtTiles.contains(tile.getId())) {
|
||||
tileType += (int) Math.pow(2, p);
|
||||
@@ -68,19 +88,10 @@ public class GameMap {
|
||||
}
|
||||
|
||||
tileType -= 16;
|
||||
logger.debug(tileType);
|
||||
|
||||
int tileId = tileTypeToId(tileType);
|
||||
|
||||
tileMap.setTile(tileId, (int) coord.x, (int) coord.y);
|
||||
|
||||
return tileType;
|
||||
}
|
||||
|
||||
public void render(SpriteBatch spriteBatch) {
|
||||
this.tileMap.render(spriteBatch);
|
||||
}
|
||||
|
||||
|
||||
private int tileTypeToId(int tileType) {
|
||||
return switch (tileType) {
|
||||
case 2, 3, 6, 7, 71, 323, 327, 66, 322, 67, 258, 259, 263, 262, 326, 70 -> 10; // down
|
||||
|
||||
Reference in New Issue
Block a user