Search in sources :

Example 26 with TiledMapTileLayer

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

the class Player method collectCheese.

/** Handle the player collecting cheese. */
private void collectCheese() {
    Rectangle thisBox = getBoundingRectangle();
    for (int i = 0; i < maze.cheeseBoxes.size; i++) {
        if (thisBox.overlaps(maze.cheeseBoxes.get(i))) {
            TiledMapTileLayer layer = (TiledMapTileLayer) maze.map.getLayers().get(MapFactory.ITEM_LAYER);
            int x = (int) maze.cheeseBoxes.get(i).x;
            int y = (int) maze.cheeseBoxes.get(i).y;
            layer.setCell(x, y, null);
            maze.cheeseBoxes.removeIndex(i);
            lives++;
            maze.updateLives(-1);
            break;
        }
    }
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Rectangle(com.badlogic.gdx.math.Rectangle)

Example 27 with TiledMapTileLayer

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project high-flyer by sangngh.

the class Player method getCell.

private Cell getCell(float x, float y) {
    TiledMapTileLayer backgroundLayer = getBuildingLayer();
    int tileX = (int) (x / backgroundLayer.getTileWidth());
    int tileY = (int) (y / backgroundLayer.getTileHeight());
    return backgroundLayer.getCell(tileX, tileY);
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer)

Example 28 with TiledMapTileLayer

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project ultimate-java by pantinor.

the class UltimaTiledMapLoader method load.

public TiledMap load() {
    TiledMap map = new TiledMap();
    MapProperties mapProperties = map.getProperties();
    mapProperties.put("name", gameMap.toString());
    mapProperties.put("id", gameMap.getId());
    mapProperties.put("orientation", "orthogonal");
    mapProperties.put("width", mapWidth);
    mapProperties.put("height", mapHeight);
    mapProperties.put("tilewidth", tileWidth);
    mapProperties.put("tileheight", tileHeight);
    mapProperties.put("backgroundcolor", "#000000");
    TiledMapTileLayer layer = new TiledMapTileLayer(mapWidth, mapHeight, tileWidth, tileHeight);
    layer.setName("Map Layer");
    layer.setVisible(true);
    for (int y = 0; y < mapHeight; y++) {
        for (int x = 0; x < mapWidth; x++) {
            Tile ct = gameMap.getMap().getTile(x, y);
            Cell cell = new Cell();
            Array<TextureAtlas.AtlasRegion> tileRegions = atlas.findRegions(ct.getName());
            Array<StaticTiledMapTile> ar = new Array<>();
            for (TextureAtlas.AtlasRegion r : tileRegions) {
                ar.add(new StaticTiledMapTile(r));
            }
            if (ar.size == 0) {
                System.out.println(ct.getName());
            }
            TiledMapTile tmt = null;
            if (tileRegions.size > 1) {
                tmt = new AnimatedTiledMapTile(.7f, ar);
            } else {
                tmt = ar.first();
            }
            tmt.setId(y * mapWidth + x);
            cell.setTile(tmt);
            layer.setCell(x, mapHeight - 1 - y, cell);
        }
    }
    map.getLayers().add(layer);
    if (gameMap.getMap().getType() == MapType.combat) {
        try {
            loadCombatPositions(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return map;
}
Also used : AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) MapProperties(com.badlogic.gdx.maps.MapProperties) AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) Tile(objects.Tile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Array(com.badlogic.gdx.utils.Array) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)

Example 29 with TiledMapTileLayer

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project ultimate-java by pantinor.

the class Utils method setTMXMap.

public static void setTMXMap(BaseMap map, Maps id, String tmxFile, TileSet ts) {
    List<Person> people = new ArrayList<>();
    Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
    TmxMapLoader loader = new TmxMapLoader();
    TiledMap tm = loader.load("assets/tilemaps/" + tmxFile);
    TiledMapTileLayer ml = (TiledMapTileLayer) tm.getLayers().get(map.getId() + "-map");
    if (ml != null) {
        FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
        TextureAtlas.TextureAtlasData atlas = new TextureAtlas.TextureAtlasData(f, f.parent(), false);
        int png_grid_width = 24;
        Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = x + (y * png_grid_width) + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        for (int y = 0; y < map.getHeight(); y++) {
            for (int x = 0; x < map.getWidth(); x++) {
                StaticTiledMapTile tr = (StaticTiledMapTile) ml.getCell(x, map.getWidth() - 1 - y).getTile();
                Tile tile = mapTileIds[tr.getId()];
                if (tile == null) {
                    tile = ts.getTileByIndex(127);
                }
                tiles[x + (y * map.getWidth())] = tile;
            }
        }
    }
    MapLayer objectsLayer = tm.getLayers().get(map.getId() + "-people");
    if (objectsLayer != null) {
        Iterator<MapObject> iter = objectsLayer.getObjects().iterator();
        while (iter.hasNext()) {
            MapObject obj = iter.next();
            Person p = new Person();
            Conversation conv = new Conversation();
            conv.setName(obj.getName());
            conv.setMap(id);
            p.setConversation(conv);
            people.add(p);
            Iterator<String> keys = obj.getProperties().getKeys();
            while (keys.hasNext()) {
                String key = keys.next();
                String value = obj.getProperties().get(key).toString();
                if (key.equals("tileType")) {
                    Tile tile = ts.getTileByName(value);
                    p.setTileIndex(tile.getIndex());
                    p.setTile(tile);
                } else if (key.equals("startX")) {
                    p.setStart_x(new Float(value).intValue());
                } else if (key.equals("startY")) {
                    p.setStart_y(new Float(value).intValue());
                } else if (key.equals("role")) {
                    PersonRole role = new PersonRole();
                    role.setInventoryType(InventoryType.valueOf(value));
                    p.setRole(role);
                } else if (key.equals("movement")) {
                    p.setMovement(ObjectMovementBehavior.valueOf(value));
                } else if (key.startsWith("description")) {
                    conv.setDescription(value);
                    conv.getTopics().add(conv.new Topic(standardQuery[2], value, null, null, null));
                } else if (key.startsWith("topic")) {
                    String[] splits = value.split(",");
                    if (splits.length == 5) {
                        conv.getTopics().add(conv.new Topic(splits[0], splits[1], splits[2], splits[3], splits[4]));
                    } else {
                        conv.getTopics().add(conv.new Topic(splits[0], splits[1], null, null, null));
                    }
                }
            }
        }
    }
    map.getCity().setPeople(people);
    map.setTiles(tiles);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MapLayer(com.badlogic.gdx.maps.MapLayer) ArrayList(java.util.ArrayList) Conversation(objects.Conversation) HawkwindConversation(objects.HawkwindConversation) LordBritishConversation(objects.LordBritishConversation) PersonRole(objects.PersonRole) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) MapObject(com.badlogic.gdx.maps.MapObject) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Person(objects.Person)

Example 30 with TiledMapTileLayer

use of com.badlogic.gdx.maps.tiled.TiledMapTileLayer in project ultimate-java by pantinor.

the class GameScreen method replaceTile.

public void replaceTile(String name, int x, int y) {
    if (name == null) {
        return;
    }
    TextureRegion texture = Ultima4.standardAtlas.findRegion(name);
    TiledMapTileLayer layer = (TiledMapTileLayer) context.getCurrentTiledMap().getLayers().get("Map Layer");
    Cell cell = layer.getCell(x, context.getCurrentMap().getWidth() - 1 - y);
    TiledMapTile tmt = new StaticTiledMapTile(texture);
    tmt.setId(y * context.getCurrentMap().getWidth() + x);
    cell.setTile(tmt);
    context.getCurrentMap().setTile(Ultima4.baseTileSet.getTileByName(name), x, y);
}
Also used : 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) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)

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