Search in sources :

Example 1 with Level

use of net.catacombsnatch.game.world.level.Level in project Catacomb-Snatch by Catacomb-Snatch.

the class RandomLevelGenerator method generate.

@Override
public Level generate(Campaign campaign) {
    /*
         * Some thoughts on generation:
		 *
		 * - Divide up the level into a grid of cells (size is customizable).
		 * - Pick a center point in each cell.
		 * - Join each pair in the list of center points with corridors.
		 * - Build a room around each center point.
		 * - Fill each room with floor tiles and put wall tiles around it (maybe add some decoration?).
		 * - Where a room wall crosses a corridor replace with a destroyable wall tile.
		 *
		 * This ensures the entire level will be connected.
		 */
    // TODO
    Level level = new Level(campaign, this, width + 1, height + 1);
    if (cellMap == null) {
        cellMap = new IntMap<>();
    } else {
        cellMap.clear();
    }
    //Place cells with their type dependent of position
    for (int cx = 0; cx < width / segwidth; cx++) {
        for (int cy = 0; cy < height / segheight; cy++) {
            Type type = Type.INNER;
            if (cy == 0 || cy == 1 || cy == height / segheight - 2 || cy == height / segheight - 1) {
                boolean isEntrance = false;
                for (int i = -1; i <= 1; i++) {
                    if (cx == (width / segwidth) / 2 + i || cy == (height / segheight) / 2 + i) {
                        isEntrance = true;
                    }
                }
                if (cy == 0 || cy == (height / segheight) - 1) {
                    if (isEntrance) {
                        type = Type.FLOOR;
                    } else {
                        type = Type.BORDER;
                    }
                } else {
                    if (isEntrance) {
                        type = Type.FLOOR;
                    }
                }
            }
            Cell cell = new Cell(cx, cy, segwidth, segheight, type);
            cellMap.put(cx + cy * width / segwidth, cell);
        }
    }
    //Generate cells
    for (Cell cell : cellMap.values()) {
        if (cell == null) {
            continue;
        }
        cell.generate(level, cellMap);
    }
    return level;
}
Also used : Type(net.catacombsnatch.game.world.level.generator.RandomLevelGenerator.Cell.Type) Level(net.catacombsnatch.game.world.level.Level)

Example 2 with Level

use of net.catacombsnatch.game.world.level.Level in project Catacomb-Snatch by Catacomb-Snatch.

the class GameScene method tick.

@Override
public void tick(float delta) {
    if (campaign.hasFinished()) {
        SceneManager.exit();
        return;
    }
    if (!paused) {
        // Tick, tock - the campaign is just a clock...
        campaign.tick(delta);
        // Prepare views for rendering and level initialization
        if (views == null) {
            final Level level = campaign.getCurrentLevel();
            views = new LinkedList<>();
            for (Player player : campaign.players) {
                if (!(player instanceof LocalPlayer))
                    continue;
                final View view = new View(level);
                view.setTarget(player.createEntity(level).getComponent(Position.class).xy());
                views.add(view);
            }
            // Update viewports
            update(true);
        }
        // Player movement
        int mx = 0, my = 0;
        if (InputManager.isPressed(Key.MOVE_LEFT))
            mx--;
        if (InputManager.isPressed(Key.MOVE_RIGHT))
            mx++;
        if (InputManager.isPressed(Key.MOVE_UP))
            my++;
        if (InputManager.isPressed(Key.MOVE_DOWN))
            my--;
        for (Entity player : campaign.getCurrentLevel().players) {
            Entities.velocity.get(player).add(mx << 2, my << 2);
        }
    }
    // Open the windows to see what's happening!
    getBatch().begin();
    for (View view : views) {
        view.render(this);
    }
    getBatch().end();
    // Just some overlays
    super.tick(delta);
}
Also used : Entity(com.badlogic.ashley.core.Entity) LocalPlayer(net.catacombsnatch.game.player.LocalPlayer) Player(net.catacombsnatch.game.player.Player) LocalPlayer(net.catacombsnatch.game.player.LocalPlayer) Level(net.catacombsnatch.game.world.level.Level) View(net.catacombsnatch.game.world.level.View)

Example 3 with Level

use of net.catacombsnatch.game.world.level.Level in project Catacomb-Snatch by Catacomb-Snatch.

the class Campaign method tick.

@Override
public void tick(float delta) {
    if (hasFinished())
        return;
    if (currentLevel == null || currentLevel.hasFinished()) {
        final Level next = rotation.getNext(levels);
        if (next == null) {
            setFinished(true);
            return;
        }
        currentLevel = next;
    }
    currentLevel.tick(delta);
}
Also used : Level(net.catacombsnatch.game.world.level.Level)

Example 4 with Level

use of net.catacombsnatch.game.world.level.Level in project Catacomb-Snatch by Catacomb-Snatch.

the class DebugLevelGenerator method generate.

@Override
public Level generate(Campaign campaign) {
    final int registered = Tiles.getRegistered().size();
    final Level level = new Level(campaign, this, registered, 1);
    int i = 0;
    for (String type : Tiles.getRegistered()) {
        Tiles.createAndAdd(type, level, i++, 0);
    }
    return level;
}
Also used : Level(net.catacombsnatch.game.world.level.Level)

Example 5 with Level

use of net.catacombsnatch.game.world.level.Level 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

Level (net.catacombsnatch.game.world.level.Level)6 Entity (com.badlogic.ashley.core.Entity)2 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 Destroyable (net.catacombsnatch.game.entity.components.Destroyable)1 LocalPlayer (net.catacombsnatch.game.player.LocalPlayer)1 Player (net.catacombsnatch.game.player.Player)1 View (net.catacombsnatch.game.world.level.View)1 Type (net.catacombsnatch.game.world.level.generator.RandomLevelGenerator.Cell.Type)1 GeneratorStringOption (net.catacombsnatch.game.world.level.generator.options.GeneratorStringOption)1