Search in sources :

Example 1 with GeneratorStringOption

use of net.catacombsnatch.game.world.level.generator.options.GeneratorStringOption 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)

Aggregations

MapLayer (com.badlogic.gdx.maps.MapLayer)1 MapObject (com.badlogic.gdx.maps.MapObject)1 MapObjects (com.badlogic.gdx.maps.MapObjects)1 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)1 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Level (net.catacombsnatch.game.world.level.Level)1 GeneratorStringOption (net.catacombsnatch.game.world.level.generator.options.GeneratorStringOption)1