Search in sources :

Example 6 with Cell

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell in project libgdx by libgdx.

the class TiledMapBench method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 320, 320);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    {
        tiles = new Texture(Gdx.files.internal("data/maps/tiled/tiles.png"));
        TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32);
        map = new TiledMap();
        MapLayers layers = map.getLayers();
        for (int l = 0; l < 20; l++) {
            TiledMapTileLayer layer = new TiledMapTileLayer(150, 100, 32, 32);
            for (int x = 0; x < 150; x++) {
                for (int y = 0; y < 100; y++) {
                    int ty = (int) (Math.random() * splitTiles.length);
                    int tx = (int) (Math.random() * splitTiles[ty].length);
                    Cell cell = new Cell();
                    cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx]));
                    layer.setCell(x, y, cell);
                }
            }
            layers.add(layer);
        }
    }
    renderer = new OrthogonalTiledMapRenderer(map);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapLayers(com.badlogic.gdx.maps.MapLayers)

Example 7 with Cell

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell in project AmazingMaze by TheVirtualMachine.

the class MapFactory method placeUpperCircuit.

/**
	 * Place the given circuit on the given layer.
	 * It is placed at the top, facing down.
	 *
	 * @param layer the layer to place the circuit on.
	 * @param circuit the circuit to use.
	 * @param location the location of the gate being placed.
	 */
private void placeUpperCircuit(TiledMapTileLayer layer, Circuit circuit, Point location) {
    Cell gate = new Cell();
    gate.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.GATE_RANGE, Circuit.getID(circuit.getGate()), TileIDs.UNKNOWN, TileIDs.DOWN_GATE)));
    layer.setCell(location.x, location.y, gate);
    gateLocations.add(new Point(location));
    Cell inputAStart = new Cell();
    int inputAPowerID = circuit.isInputA() ? TileIDs.ON : TileIDs.OFF;
    inputAStart.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, inputAPowerID)));
    layer.setCell(location.x - 1, location.y + 1, inputAStart);
    Cell inputATurn = new Cell();
    inputATurn.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, inputAPowerID, TileIDs.UP_RIGHT)));
    layer.setCell(location.x - 1, location.y, inputATurn);
    Cell inputBStart = new Cell();
    int inputBPowerID = circuit.isInputB() ? TileIDs.ON : TileIDs.OFF;
    inputBStart.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, inputBPowerID)));
    layer.setCell(location.x + 1, location.y + 1, inputBStart);
    Cell inputBTurn = new Cell();
    inputBTurn.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, inputBPowerID, TileIDs.UP_LEFT)));
    layer.setCell(location.x + 1, location.y, inputBTurn);
}
Also used : Point(java.awt.Point) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) Point(java.awt.Point)

Example 8 with Cell

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell 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 9 with Cell

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell in project AmazingMaze by TheVirtualMachine.

the class MapFactory method placeLowerCircuit.

/**
	 * Place the given circuit on the given layer.
	 * It is placed at the bottom, facing up.
	 *
	 * @param layer the layer to place the circuit on.
	 * @param circuit the circuit to use.
	 * @param location the location of the gate being placed.
	 */
private void placeLowerCircuit(TiledMapTileLayer layer, Circuit circuit, Point location) {
    Cell gate = new Cell();
    gate.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.GATE_RANGE, Circuit.getID(circuit.getGate()), TileIDs.UNKNOWN, TileIDs.UP_GATE)));
    layer.setCell(location.x, location.y, gate);
    gateLocations.add(new Point(location));
    Cell inputAStart = new Cell();
    int inputAPowerID = circuit.isInputA() ? TileIDs.ON : TileIDs.OFF;
    inputAStart.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, inputAPowerID)));
    layer.setCell(location.x - 1, location.y - 1, inputAStart);
    Cell inputATurn = new Cell();
    inputATurn.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, inputAPowerID, TileIDs.DOWN_RIGHT)));
    layer.setCell(location.x - 1, location.y, inputATurn);
    Cell inputBStart = new Cell();
    int inputBPowerID = circuit.isInputB() ? TileIDs.ON : TileIDs.OFF;
    inputBStart.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, inputBPowerID)));
    layer.setCell(location.x + 1, location.y - 1, inputBStart);
    Cell inputBTurn = new Cell();
    inputBTurn.setTile(assets.tiles.getTile(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, inputBPowerID, TileIDs.DOWN_LEFT)));
    layer.setCell(location.x + 1, location.y, inputBTurn);
}
Also used : Point(java.awt.Point) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) Point(java.awt.Point)

Example 10 with Cell

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell 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)

Aggregations

Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)19 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)13 Point (java.awt.Point)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)5 Color (com.badlogic.gdx.graphics.Color)3 Texture (com.badlogic.gdx.graphics.Texture)3 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)3 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 MapLayers (com.badlogic.gdx.maps.MapLayers)2 Rectangle (com.badlogic.gdx.math.Rectangle)2 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)2 Element (com.badlogic.gdx.utils.XmlReader.Element)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 MapLayer (com.badlogic.gdx.maps.MapLayer)1 MapObject (com.badlogic.gdx.maps.MapObject)1 MapObjects (com.badlogic.gdx.maps.MapObjects)1 HexagonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer)1