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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations