Search in sources :

Example 1 with Type

use of net.catacombsnatch.game.world.level.generator.RandomLevelGenerator.Cell.Type 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)

Aggregations

Level (net.catacombsnatch.game.world.level.Level)1 Type (net.catacombsnatch.game.world.level.generator.RandomLevelGenerator.Cell.Type)1