Search in sources :

Example 16 with Room

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;
        }
    }
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) PitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom) ShopRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom) SpecialRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom) ExitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom) SecretRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)

Example 17 with Room

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);
        }
    }
}
Also used : Collection(java.util.Collection) ExitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) PitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom) ShopRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom) SpecialRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom) ExitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom) SecretRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom)

Example 18 with Room

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);
}
Also used : ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) PitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom) ShopRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom) SpecialRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom) ExitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom) SecretRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom)

Example 19 with Room

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;
}
Also used : ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)

Example 20 with Room

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;
}
Also used : ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)

Aggregations

Room (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)28 ArrayList (java.util.ArrayList)15 StandardRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)11 EntranceRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom)10 ExitRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom)9 SecretRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom)8 ShopRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom)8 EmptyRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom)8 Point (com.watabou.utils.Point)7 PitRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom)6 SpecialRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom)6 Rect (com.watabou.utils.Rect)6 ConnectionRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)5 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)2 RegularLevel (com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel)2 MazeConnectionRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom)2 RatKingRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.RatKingRoom)2 SewerBossEntranceRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.SewerBossEntranceRoom)2 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)1 Buff (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff)1