Search in sources :

Example 21 with TiledMapTileLayer

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

the class SuperKoalio method renderDebug.

private void renderDebug() {
    debugRenderer.setProjectionMatrix(camera.combined);
    debugRenderer.begin(ShapeType.Line);
    debugRenderer.setColor(Color.RED);
    debugRenderer.rect(koala.position.x, koala.position.y, Koala.WIDTH, Koala.HEIGHT);
    debugRenderer.setColor(Color.YELLOW);
    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("walls");
    for (int y = 0; y <= layer.getHeight(); y++) {
        for (int x = 0; x <= layer.getWidth(); x++) {
            Cell cell = layer.getCell(x, y);
            if (cell != null) {
                if (camera.frustum.boundsInFrustum(x + 0.5f, y + 0.5f, 0, 1, 1, 0))
                    debugRenderer.rect(x, y, 1, 1);
            }
        }
    }
    debugRenderer.end();
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)

Example 22 with TiledMapTileLayer

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project Catacomb-Snatch by Catacomb-Snatch.

the class TmxLevelGenerator method generate.

@Override
public Level generate(Campaign campaign) {
    Level level = null;
    final GeneratorStringOption empty = (GeneratorStringOption) getOption("emptyTile");
    final boolean fill = empty.value != null && Tiles.isRegistered(empty.value);
    for (MapLayer layer : map.getLayers()) {
        if (layer instanceof TiledMapTileLayer) {
            // Tile layer - the first one always decides the map size
            final TiledMapTileLayer tileLayer = (TiledMapTileLayer) layer;
            if (level == null) {
                level = new Level(campaign, this, tileLayer.getWidth(), tileLayer.getHeight());
            }
            for (int x = 0; x < tileLayer.getWidth(); x++) {
                for (int y = 0; y < tileLayer.getHeight(); y++) {
                    final Cell cell = tileLayer.getCell(x, y);
                    final String type = (cell == null || cell.getTile() == null) ? (fill ? empty.value : null) : (String) cell.getTile().getProperties().get("type");
                    if (type != null) {
                        Tiles.createAndAdd(type, level, x, y);
                    }
                }
            }
        } else {
            // Object layer for additional entities (monsters, spawn points, triggers)
            final MapObjects objects = layer.getObjects();
            for (int i = 0; i < objects.getCount(); i++) {
                MapObject obj = objects.get(i);
                String type = obj.getProperties().get("type", String.class);
                if ("spawnPoint".equalsIgnoreCase(type)) {
                    float x = obj.getProperties().get("x", Float.class);
                    float y = obj.getProperties().get("y", Float.class);
                    spawns.add(new Vector2(x, y).add(0.5f, 0.5f));
                }
            }
        }
    }
    // Safety check
    if (level == null) {
        return null;
    }
    return level;
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Vector2(com.badlogic.gdx.math.Vector2) MapLayer(com.badlogic.gdx.maps.MapLayer) Level(net.catacombsnatch.game.world.level.Level) GeneratorStringOption(net.catacombsnatch.game.world.level.generator.options.GeneratorStringOption) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapObjects(com.badlogic.gdx.maps.MapObjects) MapObject(com.badlogic.gdx.maps.MapObject)

Example 23 with TiledMapTileLayer

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

the class MazeScreen method updateWires.

/**
	 * Update the wires connected to the gate at (x, y).
	 *
	 * @param x the x position of the gate being updated.
	 * @param y the y position of the gate being updated.
	 * @param state the new state of the wires.
	 */
private void updateWires(int x, int y, int state) {
    TiledMapTileLayer wires = (TiledMapTileLayer) map.getLayers().get(MapFactory.WIRE_LAYER);
    for (int r = y + 1; r < mapHeight; r++) {
        if (wires.getCell(x, r) != null) {
            Cell cell = wires.getCell(x, r);
            int newID = TileIDs.stripElectricState(cell.getTile().getId());
            newID = TileIDs.computeID(newID, state);
            cell.setTile(game.assets.tiles.getTile(newID));
        } else {
            break;
        }
    }
    for (int r = y - 1; r >= 0; r--) {
        if (wires.getCell(x, r) != null) {
            Cell cell = wires.getCell(x, r);
            int newID = TileIDs.stripElectricState(cell.getTile().getId());
            newID = TileIDs.computeID(newID, state);
            cell.setTile(game.assets.tiles.getTile(newID));
        } else {
            break;
        }
    }
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) Point(java.awt.Point)

Example 24 with TiledMapTileLayer

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

the class MazeScreen method createBoundingBoxes.

/** Create the bounding boxes for collision detection. */
private void createBoundingBoxes() {
    obstacleBoxes = new Array<Rectangle>(false, 16);
    TiledMapTileLayer objects = (TiledMapTileLayer) map.getLayers().get(MapFactory.OBJECT_LAYER);
    for (int r = 0; r < mapHeight; r++) {
        for (int c = 0; c < mapWidth; c++) {
            Cell cell = objects.getCell(c, r);
            if (cell != null) {
                obstacleBoxes.add(new Rectangle(c, r, 1, 1));
            }
        }
    }
    wireBoxes = new Array<Rectangle>(false, 16);
    TiledMapTileLayer wires = (TiledMapTileLayer) map.getLayers().get(MapFactory.WIRE_LAYER);
    for (int r = 0; r < mapHeight; r++) {
        for (int c = 0; c < mapWidth; c++) {
            WireCell wire = (WireCell) wires.getCell(c, r);
            if (wire != null && wire.isOn()) {
                wireBoxes.add(new Rectangle(c + 5f / 16f, r, 6f / 16f, 1));
            }
        }
    }
    fishBoxes = new Array<Rectangle>(false, 16);
    cheeseBoxes = new Array<Rectangle>(false, 16);
    TiledMapTileLayer items = (TiledMapTileLayer) map.getLayers().get(MapFactory.ITEM_LAYER);
    for (int r = 0; r < mapHeight; r++) {
        for (int c = 0; c < mapWidth; c++) {
            Cell item = items.getCell(c, r);
            if (item != null) {
                if (item.getClass() == FishCell.class) {
                    fishBoxes.add(new Rectangle(c, r, 1, 1));
                } else {
                    cheeseBoxes.add(new Rectangle(c, r, 1, 1));
                }
            }
        }
    }
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Rectangle(com.badlogic.gdx.math.Rectangle) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) Point(java.awt.Point)

Example 25 with TiledMapTileLayer

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

the class Player method collectFish.

/** Handle the player collecting fish. */
private void collectFish() {
    Rectangle thisBox = getBoundingRectangle();
    for (int i = 0; i < maze.fishBoxes.size; i++) {
        if (thisBox.overlaps(maze.fishBoxes.get(i))) {
            TiledMapTileLayer layer = (TiledMapTileLayer) maze.map.getLayers().get(MapFactory.ITEM_LAYER);
            int x = (int) maze.fishBoxes.get(i).x;
            int y = (int) maze.fishBoxes.get(i).y;
            FishColour colour = ((FishCell) layer.getCell(x, y)).getColour();
            layer.setCell(x, y, null);
            maze.fishBoxes.removeIndex(i);
            switch(colour) {
                case BLUE:
                    blueCollected++;
                    break;
                case PURPLE:
                    purpleCollected++;
                    break;
                case GREEN:
                    greenCollected++;
                    break;
                case RED:
                    redCollected++;
                    break;
                case ORANGE:
                    orangeCollected++;
                    break;
            }
            break;
        }
    }
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Rectangle(com.badlogic.gdx.math.Rectangle) FishColour(ca.hiphiparray.amazingmaze.FishCell.FishColour)

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