Search in sources :

Example 1 with TiledMapTileLayer

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;
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Point(java.awt.Point) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) Point(java.awt.Point)

Example 2 with TiledMapTileLayer

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;
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Vector3(com.badlogic.gdx.math.Vector3) Point(java.awt.Point) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) Point(java.awt.Point)

Example 3 with TiledMapTileLayer

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);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) HexagonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapLayers(com.badlogic.gdx.maps.MapLayers)

Example 4 with TiledMapTileLayer

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();
}
Also used : TiledMapImageLayer(com.badlogic.gdx.maps.tiled.TiledMapImageLayer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) MapLayer(com.badlogic.gdx.maps.MapLayer)

Example 5 with TiledMapTileLayer

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();
}
Also used : TiledMapImageLayer(com.badlogic.gdx.maps.tiled.TiledMapImageLayer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) MapLayer(com.badlogic.gdx.maps.MapLayer)

Aggregations

TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)31 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)18 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)12 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)11 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)9 MapLayer (com.badlogic.gdx.maps.MapLayer)7 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)7 Rectangle (com.badlogic.gdx.math.Rectangle)5 Color (com.badlogic.gdx.graphics.Color)4 MapLayers (com.badlogic.gdx.maps.MapLayers)4 TiledMapImageLayer (com.badlogic.gdx.maps.tiled.TiledMapImageLayer)4 Point (java.awt.Point)4 Tile (objects.Tile)4 Texture (com.badlogic.gdx.graphics.Texture)3 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)3 MapProperties (com.badlogic.gdx.maps.MapProperties)3 AnimatedTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 MapObject (com.badlogic.gdx.maps.MapObject)2 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)2