use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularLevel method createMobs.
@Override
protected void createMobs() {
// on floor 1, 10 rats are created so the player can get level 2.
int mobsToSpawn = Dungeon.depth == 1 ? 10 : nMobs();
ArrayList<Room> stdRooms = new ArrayList<>();
for (Room room : rooms) {
if (room instanceof StandardRoom && room != roomEntrance) {
for (int i = 0; i < ((StandardRoom) room).sizeCat.roomValue; i++) {
stdRooms.add(room);
}
// pre-0.6.0 save compatibility
} else if (room.legacyType.equals("STANDARD")) {
stdRooms.add(room);
}
}
Random.shuffle(stdRooms);
Iterator<Room> stdRoomIter = stdRooms.iterator();
while (mobsToSpawn > 0) {
if (!stdRoomIter.hasNext())
stdRoomIter = stdRooms.iterator();
Room roomToSpawn = stdRoomIter.next();
Mob mob = createMob();
mob.pos = pointToCell(roomToSpawn.random());
if (findMob(mob.pos) == null && passable[mob.pos] && mob.pos != exit) {
mobsToSpawn--;
mobs.add(mob);
// TODO: perhaps externalize this logic into a method. Do I want to make mobs more likely to clump deeper down?
if (mobsToSpawn > 0 && Random.Int(4) == 0) {
mob = createMob();
mob.pos = pointToCell(roomToSpawn.random());
if (findMob(mob.pos) == null && passable[mob.pos] && mob.pos != exit) {
mobsToSpawn--;
mobs.add(mob);
}
}
}
}
for (Mob m : mobs) {
if (map[m.pos] == Terrain.HIGH_GRASS) {
map[m.pos] = Terrain.GRASS;
losBlocking[m.pos] = false;
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularLevel method restoreFromBundle.
@SuppressWarnings("unchecked")
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
rooms = new ArrayList<>((Collection<Room>) ((Collection<?>) bundle.getCollection("rooms")));
for (Room r : rooms) {
r.onLevelLoad(this);
if (r instanceof EntranceRoom || r.legacyType.equals("ENTRANCE")) {
roomEntrance = r;
} else if (r instanceof ExitRoom || r.legacyType.equals("EXIT")) {
roomExit = r;
}
}
if (bundle.contains("mobs_to_spawn")) {
for (Class<? extends Mob> mob : bundle.getClassArray("mobs_to_spawn")) {
if (mob != null)
mobsToSpawn.add(mob);
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularLevel method build.
@Override
protected boolean build() {
builder = builder();
ArrayList<Room> initRooms = initRooms();
Random.shuffle(initRooms);
do {
for (Room r : initRooms) {
r.neigbours.clear();
r.connected.clear();
}
rooms = builder.build((ArrayList<Room>) initRooms.clone());
} while (rooms == null);
return painter().paint(this, rooms);
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class BranchesBuilder method build.
@Override
public ArrayList<Room> build(ArrayList<Room> rooms) {
setupRooms(rooms);
if (entrance == null) {
return null;
}
ArrayList<Room> branchable = new ArrayList<>();
entrance.setSize();
entrance.setPos(0, 0);
branchable.add(entrance);
if (shop != null) {
placeRoom(branchable, entrance, shop, Random.Float(360f));
}
ArrayList<Room> roomsToBranch = new ArrayList<>();
roomsToBranch.addAll(multiConnections);
if (exit != null)
roomsToBranch.add(exit);
roomsToBranch.addAll(singleConnections);
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 LineBuilder method build.
@Override
public ArrayList<Room> build(ArrayList<Room> rooms) {
setupRooms(rooms);
if (entrance == null) {
return null;
}
float direction = Random.Float(0, 360);
ArrayList<Room> branchable = new ArrayList<>();
entrance.setSize();
entrance.setPos(0, 0);
branchable.add(entrance);
if (shop != null) {
placeRoom(rooms, entrance, shop, direction + 180f);
}
int roomsOnPath = (int) (multiConnections.size() * pathLength) + Random.chances(pathLenJitterChances);
roomsOnPath = Math.min(roomsOnPath, multiConnections.size());
Room curr = entrance;
float[] pathTunnels = pathTunnelChances.clone();
for (int i = 0; i <= roomsOnPath; i++) {
if (i == roomsOnPath && exit == null)
continue;
int tunnels = Random.chances(pathTunnels);
if (tunnels == -1) {
pathTunnels = pathTunnelChances.clone();
tunnels = Random.chances(pathTunnels);
}
pathTunnels[tunnels]--;
for (int j = 0; j < tunnels; j++) {
ConnectionRoom t = ConnectionRoom.createRoom();
placeRoom(rooms, curr, t, direction + Random.Float(-pathVariance, pathVariance));
branchable.add(t);
rooms.add(t);
curr = t;
}
Room r = (i == roomsOnPath ? exit : multiConnections.get(i));
placeRoom(rooms, curr, r, direction + Random.Float(-pathVariance, pathVariance));
branchable.add(r);
curr = r;
}
ArrayList<Room> roomsToBranch = new ArrayList<>();
for (int i = roomsOnPath; i < multiConnections.size(); i++) {
roomsToBranch.add(multiConnections.get(i));
}
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;
}
Aggregations