use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class LoopBuilder method build.
@Override
public ArrayList<Room> build(ArrayList<Room> rooms) {
setupRooms(rooms);
if (entrance == null) {
return null;
}
entrance.setSize();
entrance.setPos(0, 0);
float startAngle = Random.Float(0, 360);
ArrayList<Room> loop = new ArrayList<>();
int roomsOnLoop = (int) (multiConnections.size() * pathLength) + Random.chances(pathLenJitterChances);
roomsOnLoop = Math.min(roomsOnLoop, multiConnections.size());
roomsOnLoop++;
float[] pathTunnels = pathTunnelChances.clone();
for (int i = 0; i < roomsOnLoop; i++) {
if (i == 0)
loop.add(entrance);
else
loop.add(multiConnections.remove(0));
int tunnels = Random.chances(pathTunnels);
if (tunnels == -1) {
pathTunnels = pathTunnelChances.clone();
tunnels = Random.chances(pathTunnels);
}
pathTunnels[tunnels]--;
for (int j = 0; j < tunnels; j++) {
loop.add(ConnectionRoom.createRoom());
}
}
if (exit != null)
loop.add((loop.size() + 1) / 2, exit);
Room prev = entrance;
float targetAngle;
for (int i = 1; i < loop.size(); i++) {
Room r = loop.get(i);
targetAngle = startAngle + targetAngle(i / (float) loop.size());
if (placeRoom(rooms, prev, r, targetAngle) != -1) {
prev = r;
if (!rooms.contains(prev))
rooms.add(prev);
} else {
// FIXME this is lazy, there are ways to do this without relying on chance
return null;
}
}
// should just write a general function for stitching two rooms together in builder
while (!prev.connect(entrance)) {
ConnectionRoom c = ConnectionRoom.createRoom();
if (placeRoom(loop, prev, c, angleBetweenRooms(prev, entrance)) == -1) {
return null;
}
loop.add(c);
rooms.add(c);
prev = c;
}
loopCenter = new PointF();
for (Room r : loop) {
loopCenter.x += (r.left + r.right) / 2f;
loopCenter.y += (r.top + r.bottom) / 2f;
}
loopCenter.x /= loop.size();
loopCenter.y /= loop.size();
if (shop != null) {
float angle;
int tries = 10;
do {
angle = placeRoom(loop, entrance, shop, Random.Float(360f));
tries--;
} while (angle == -1 && tries >= 0);
if (angle == -1)
return null;
}
ArrayList<Room> branchable = new ArrayList<>(loop);
ArrayList<Room> roomsToBranch = new ArrayList<>();
roomsToBranch.addAll(multiConnections);
roomsToBranch.addAll(singleConnections);
weightRooms(branchable);
createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
findNeighbours(rooms);
for (Room r : rooms) {
for (Room n : r.neigbours) {
if (!n.connected.containsKey(r) && Random.Float() < extraConnectionChance) {
r.connect(n);
}
}
}
return rooms;
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class Chasm method heroFall.
public static void heroFall(int pos) {
jumpConfirmed = false;
Sample.INSTANCE.play(Assets.SND_FALLING);
Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null)
buff.detach();
if (Dungeon.hero.isAlive()) {
Dungeon.hero.interrupt();
InterlevelScene.mode = InterlevelScene.Mode.FALL;
if (Dungeon.level instanceof RegularLevel) {
Room room = ((RegularLevel) Dungeon.level).room(pos);
InterlevelScene.fallIntoPit = room != null && room instanceof WeakFloorRoom;
} else {
InterlevelScene.fallIntoPit = false;
}
Game.switchScene(InterlevelScene.class);
} else {
Dungeon.hero.sprite.visible = false;
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class CavesPainter method decorate.
@Override
protected void decorate(Level level, ArrayList<Room> rooms) {
int w = level.width();
int l = level.length();
int[] map = level.map;
for (Room room : rooms) {
if (!(room instanceof EmptyRoom || room instanceof CaveRoom)) {
continue;
}
if (room.width() <= 4 || room.height() <= 4) {
continue;
}
int s = room.square();
if (Random.Int(s) > 8) {
int corner = (room.left + 1) + (room.top + 1) * w;
if (map[corner - 1] == Terrain.WALL && map[corner - w] == Terrain.WALL) {
map[corner] = Terrain.WALL;
level.traps.remove(corner);
}
}
if (Random.Int(s) > 8) {
int corner = (room.right - 1) + (room.top + 1) * w;
if (map[corner + 1] == Terrain.WALL && map[corner - w] == Terrain.WALL) {
map[corner] = Terrain.WALL;
level.traps.remove(corner);
}
}
if (Random.Int(s) > 8) {
int corner = (room.left + 1) + (room.bottom - 1) * w;
if (map[corner - 1] == Terrain.WALL && map[corner + w] == Terrain.WALL) {
map[corner] = Terrain.WALL;
level.traps.remove(corner);
}
}
if (Random.Int(s) > 8) {
int corner = (room.right - 1) + (room.bottom - 1) * w;
if (map[corner + 1] == Terrain.WALL && map[corner + w] == Terrain.WALL) {
map[corner] = Terrain.WALL;
level.traps.remove(corner);
}
}
for (Room n : room.connected.keySet()) {
if ((n instanceof StandardRoom || n instanceof ConnectionRoom) && Random.Int(3) == 0) {
Painter.set(level, room.connected.get(n), Terrain.EMPTY_DECO);
}
}
}
for (int i = w + 1; i < l - w; i++) {
if (map[i] == Terrain.EMPTY) {
int n = 0;
if (map[i + 1] == Terrain.WALL) {
n++;
}
if (map[i - 1] == Terrain.WALL) {
n++;
}
if (map[i + w] == Terrain.WALL) {
n++;
}
if (map[i - w] == Terrain.WALL) {
n++;
}
if (Random.Int(6) <= n) {
map[i] = Terrain.EMPTY_DECO;
}
}
}
for (int i = 0; i < l - w; i++) {
if (map[i] == Terrain.WALL && DungeonTileSheet.floorTile(map[i + w]) && Random.Int(4) == 0) {
map[i] = Terrain.WALL_DECO;
}
}
for (Room r : rooms) {
if (r instanceof EmptyRoom) {
for (Room n : r.neigbours) {
if (n instanceof EmptyRoom && !r.connected.containsKey(n)) {
Rect i = r.intersect(n);
if (i.left == i.right && i.bottom - i.top >= 5) {
i.top += 2;
i.bottom -= 1;
i.right++;
Painter.fill(level, i.left, i.top, 1, i.height(), Terrain.CHASM);
} else if (i.top == i.bottom && i.right - i.left >= 5) {
i.left += 2;
i.right -= 1;
i.bottom++;
Painter.fill(level, i.left, i.top, i.width(), 1, Terrain.CHASM);
}
}
}
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularPainter method paintDoors.
protected void paintDoors(Level l, ArrayList<Room> rooms) {
for (Room r : rooms) {
for (Room n : r.connected.keySet()) {
if (joinRooms(l, r, n)) {
continue;
}
Room.Door d = r.connected.get(n);
int door = d.x + d.y * l.width();
if (d.type == Room.Door.Type.REGULAR) {
// chance for a hidden door scales from 3/21 on floor 2 to 3/3 on floor 20
if (Dungeon.depth > 1 && (Dungeon.depth >= 20 || Random.Int(23 - Dungeon.depth) < Dungeon.depth)) {
d.type = Room.Door.Type.HIDDEN;
Graph.buildDistanceMap(rooms, r);
// don't hide if it would make this room only accessible by hidden doors
if (n.distance == Integer.MAX_VALUE) {
d.type = Room.Door.Type.UNLOCKED;
}
} else {
d.type = Room.Door.Type.UNLOCKED;
}
}
switch(d.type) {
case EMPTY:
l.map[door] = Terrain.EMPTY;
break;
case TUNNEL:
l.map[door] = l.tunnelTile();
break;
case UNLOCKED:
l.map[door] = Terrain.DOOR;
break;
case HIDDEN:
l.map[door] = Terrain.SECRET_DOOR;
break;
case BARRICADE:
l.map[door] = Terrain.BARRICADE;
break;
case LOCKED:
l.map[door] = Terrain.LOCKED_DOOR;
break;
}
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularPainter method paint.
@Override
public boolean paint(Level level, ArrayList<Room> rooms) {
// painter can be used without rooms
if (rooms != null) {
int padding = level.feeling == Level.Feeling.CHASM ? 2 : 1;
int leftMost = Integer.MAX_VALUE, topMost = Integer.MAX_VALUE;
for (Room r : rooms) {
if (r.left < leftMost)
leftMost = r.left;
if (r.top < topMost)
topMost = r.top;
}
leftMost -= padding;
topMost -= padding;
int rightMost = 0, bottomMost = 0;
for (Room r : rooms) {
r.shift(-leftMost, -topMost);
if (r.right > rightMost)
rightMost = r.right;
if (r.bottom > bottomMost)
bottomMost = r.bottom;
}
rightMost += padding;
bottomMost += padding;
// add 1 to account for 0 values
level.setSize(rightMost + 1, bottomMost + 1);
} else {
// check if the level's size was already initialized by something else
if (level.length() == 0)
return false;
// easier than checking for null everywhere
rooms = new ArrayList<>();
}
Random.shuffle(rooms);
for (Room r : rooms) {
placeDoors(r);
r.paint(level);
}
paintDoors(level, rooms);
if (waterFill > 0f) {
paintWater(level, rooms);
}
if (grassFill > 0f) {
paintGrass(level, rooms);
}
if (nTraps > 0) {
paintTraps(level, rooms);
}
decorate(level, rooms);
return true;
}
Aggregations