Search in sources :

Example 1 with TiledMap

use of com.badlogic.gdx.maps.tiled.TiledMap 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 2 with TiledMap

use of com.badlogic.gdx.maps.tiled.TiledMap 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 3 with TiledMap

use of com.badlogic.gdx.maps.tiled.TiledMap 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 4 with TiledMap

use of com.badlogic.gdx.maps.tiled.TiledMap in project Entitas-Java by Rubentxu.

the class TiledRendererSystem method initialize.

@Override
public void initialize() {
    this.cam = context.getCamera().camera;
    Tiled tiled = context.getTiled();
    TiledMap tiledMap = assetsManager.getMap(tiled.tileMapName);
    this.tiledRenderer = new OrthogonalTiledMapRenderer(tiledMap, tiled.unitScale);
}
Also used : OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) Tiled(ilargia.egdx.logicbricks.component.scene.Tiled) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap)

Example 5 with TiledMap

use of com.badlogic.gdx.maps.tiled.TiledMap in project Entitas-Java by Rubentxu.

the class TiledRendererSystem method execute.

@Override
protected void execute(List<SceneEntity> gameEntities) {
    Tiled tiled = context.getTiled();
    TiledMap tiledMap = assetsManager.getMap(tiled.tileMapName);
    tiledRenderer.setMap(tiledMap);
    tiledRenderer.setView((OrthographicCamera) cam);
}
Also used : Tiled(ilargia.egdx.logicbricks.component.scene.Tiled) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap)

Aggregations

TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)6 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)3 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 Texture (com.badlogic.gdx.graphics.Texture)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 MapLayers (com.badlogic.gdx.maps.MapLayers)2 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)2 Tiled (ilargia.egdx.logicbricks.component.scene.Tiled)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 MapObject (com.badlogic.gdx.maps.MapObject)1 MapObjects (com.badlogic.gdx.maps.MapObjects)1 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)1 HexagonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer)1 Point (java.awt.Point)1