use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project AmazingMaze by TheVirtualMachine.
the class MapFactory method generateMap.
/**
* Return a map generated with the {@link MapFactory}'s parameters.
*
* @return a tiled map.
*/
public TiledMap generateMap() {
TiledMap map = new TiledMap();
map.getTileSets().addTileSet(assets.tiles);
TiledMapTileLayer backgroundLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
backgroundLayer.setName(BACKGROUND_LAYER);
for (int c = 0; c < backgroundLayer.getWidth(); c++) {
for (int r = 0; r < backgroundLayer.getHeight(); r++) {
Cell cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BACKGROUND)));
backgroundLayer.setCell(c, r, cell);
}
}
map.getLayers().add(backgroundLayer);
final int gateSpace = 2;
final int extraRoom = 3;
List<Integer> splits = generateWireLocations();
TiledMapTileLayer objectLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
objectLayer.setName(OBJECT_LAYER);
TiledMapTileLayer wireLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
wireLayer.setName(WIRE_LAYER);
for (int col : splits) {
// Place the middle barriers and the unknown wires.
boolean upperOutput = random.nextBoolean();
Circuit upperGate = new Circuit(upperOutput, random);
Circuit lowerGate = new Circuit(!upperOutput, random);
Point highLocation = new Point(col, height - gateSpace);
Point lowLocation = new Point(col, gateSpace - 1);
if (Circuit.evaluateGate(upperGate.getGate(), upperGate.isInputA(), upperGate.isInputB())) {
gateOn.add(upperGate);
} else {
gateOn.add(lowerGate);
}
placeUpperCircuit(objectLayer, upperGate, highLocation);
placeLowerCircuit(objectLayer, lowerGate, lowLocation);
int barrierLoc = randomInt(gateSpace + extraRoom, height - (gateSpace + extraRoom));
Cell cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BARRIER)));
objectLayer.setCell(col, barrierLoc, cell);
for (int r = barrierLoc - 1; r >= gateSpace; r--) {
// Place the lower wires.
WireCell wire = new WireCell(!upperOutput);
wire.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, TileIDs.UNKNOWN)));
wireLayer.setCell(col, r, wire);
}
for (int r = barrierLoc + 1; r < height - gateSpace; r++) {
// Place the upper wires.
WireCell wire = new WireCell(upperOutput);
wire.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, TileIDs.UNKNOWN)));
wireLayer.setCell(col, r, wire);
}
}
for (int c = 0; c < width; c++) {
if (!splits.contains(c)) {
Cell cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BARRIER)));
objectLayer.setCell(c, gateSpace, cell);
cell = new Cell();
cell.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.BARRIER)));
objectLayer.setCell(c, height - gateSpace - 1, cell);
}
}
map.getLayers().add(objectLayer);
map.getLayers().add(wireLayer);
TiledMapTileLayer powerUpLayer = new TiledMapTileLayer(width, height, MazeScreen.TILE_SIZE, MazeScreen.TILE_SIZE);
powerUpLayer.setName(ITEM_LAYER);
for (int c = 1; c < width; c++) {
if (!splits.contains(c)) {
if (random.nextDouble() <= 0.25) {
placeFish(powerUpLayer, c, gateSpace);
c++;
} else if (random.nextDouble() <= 0.1) {
placeCheese(powerUpLayer, c, gateSpace);
c++;
}
}
}
map.getLayers().add(powerUpLayer);
return map;
}
use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project AmazingMaze by TheVirtualMachine.
the class MazeScreen method touchDown.
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 worldClickPos = viewport.getCamera().unproject(new Vector3(screenX, screenY, 0));
int x = (int) worldClickPos.x;
int y = (int) worldClickPos.y;
TiledMapTileLayer objects = (TiledMapTileLayer) map.getLayers().get(MapFactory.OBJECT_LAYER);
Cell gate;
int newID;
for (Point point : gateLocations) {
if (point.x == x && point.y == y) {
gate = objects.getCell(x, y);
newID = TileIDs.computeID(TileIDs.stripElectricState(gate.getTile().getId()));
if (button == Buttons.LEFT) {
newID = TileIDs.computeID(newID, TileIDs.ON);
updateWires(x, y, TileIDs.ON);
} else if (button == Buttons.RIGHT) {
newID = TileIDs.computeID(newID, TileIDs.OFF);
updateWires(x, y, TileIDs.OFF);
} else if (button == Buttons.MIDDLE) {
newID = TileIDs.computeID(newID, TileIDs.UNKNOWN);
updateWires(x, y, TileIDs.UNKNOWN);
} else {
return true;
}
gate.setTile(game.assets.tiles.getTile(newID));
break;
}
}
return true;
}
use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project libgdx by libgdx.
the class HexagonalTiledMapTest method create.
@Override
public void create() {
super.create();
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, (w / h) * 480, 480);
camera.update();
cameraController = new OrthoCamController(camera);
Gdx.input.setInputProcessor(cameraController);
hexture = new Texture(Gdx.files.internal("data/maps/tiled/hex/hexes.png"));
TextureRegion[][] hexes = TextureRegion.split(hexture, 112, 97);
map = new TiledMap();
MapLayers layers = map.getLayers();
TiledMapTile[] tiles = new TiledMapTile[3];
tiles[0] = new StaticTiledMapTile(new TextureRegion(hexes[0][0]));
tiles[1] = new StaticTiledMapTile(new TextureRegion(hexes[0][1]));
tiles[2] = new StaticTiledMapTile(new TextureRegion(hexes[1][0]));
for (int l = 0; l < 1; l++) {
TiledMapTileLayer layer = new TiledMapTileLayer(45, 30, 112, 97);
for (int y = 0; y < 30; y++) {
for (int x = 0; x < 45; x++) {
int id = (int) (Math.random() * 3);
Cell cell = new Cell();
cell.setTile(tiles[id]);
layer.setCell(x, y, cell);
}
}
layers.add(layer);
}
renderer = new HexagonalTiledMapRenderer(map);
}
use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project libgdx by libgdx.
the class BatchTiledMapRenderer method render.
@Override
public void render() {
beginRender();
for (MapLayer layer : map.getLayers()) {
if (layer.isVisible()) {
if (layer instanceof TiledMapTileLayer) {
renderTileLayer((TiledMapTileLayer) layer);
} else if (layer instanceof TiledMapImageLayer) {
renderImageLayer((TiledMapImageLayer) layer);
} else {
renderObjects(layer);
}
}
}
endRender();
}
use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project libgdx by libgdx.
the class BatchTiledMapRenderer method render.
@Override
public void render(int[] layers) {
beginRender();
for (int layerIdx : layers) {
MapLayer layer = map.getLayers().get(layerIdx);
if (layer.isVisible()) {
if (layer instanceof TiledMapTileLayer) {
renderTileLayer((TiledMapTileLayer) layer);
} else if (layer instanceof TiledMapImageLayer) {
renderImageLayer((TiledMapImageLayer) layer);
} else {
renderObjects(layer);
}
}
}
endRender();
}
Aggregations