Search in sources :

Example 6 with Room

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.

the class RegularBuilder method createBranches.

// places the rooms in roomsToBranch into branches from rooms in branchable.
// note that the three arrays should be separate, they may contain the same rooms however
protected void createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable, ArrayList<Room> roomsToBranch, float[] connChances) {
    int i = 0;
    float angle;
    int tries;
    Room curr;
    ArrayList<Room> connectingRoomsThisBranch = new ArrayList<>();
    float[] connectionChances = connChances.clone();
    while (i < roomsToBranch.size()) {
        Room r = roomsToBranch.get(i);
        connectingRoomsThisBranch.clear();
        do {
            curr = Random.element(branchable);
        } while (r instanceof SecretRoom && curr instanceof ConnectionRoom);
        int connectingRooms = Random.chances(connectionChances);
        if (connectingRooms == -1) {
            connectionChances = connChances.clone();
            connectingRooms = Random.chances(connectionChances);
        }
        connectionChances[connectingRooms]--;
        for (int j = 0; j < connectingRooms; j++) {
            ConnectionRoom t = r instanceof SecretRoom ? new MazeConnectionRoom() : ConnectionRoom.createRoom();
            tries = 3;
            do {
                angle = placeRoom(rooms, curr, t, randomBranchAngle(curr));
                tries--;
            } while (angle == -1 && tries > 0);
            if (angle == -1) {
                for (Room c : connectingRoomsThisBranch) {
                    c.clearConnections();
                    rooms.remove(c);
                }
                connectingRoomsThisBranch.clear();
                break;
            } else {
                connectingRoomsThisBranch.add(t);
                rooms.add(t);
            }
            curr = t;
        }
        if (connectingRoomsThisBranch.size() != connectingRooms) {
            continue;
        }
        tries = 10;
        do {
            angle = placeRoom(rooms, curr, r, randomBranchAngle(curr));
            tries--;
        } while (angle == -1 && tries > 0);
        if (angle == -1) {
            for (Room t : connectingRoomsThisBranch) {
                t.clearConnections();
                rooms.remove(t);
            }
            connectingRoomsThisBranch.clear();
            continue;
        }
        for (int j = 0; j < connectingRoomsThisBranch.size(); j++) {
            if (Random.Int(3) <= 1)
                branchable.add(connectingRoomsThisBranch.get(j));
        }
        if (r.maxConnections(Room.ALL) > 1 && Random.Int(3) == 0) {
            if (r instanceof StandardRoom) {
                for (int j = 0; j < ((StandardRoom) r).sizeCat.connectionWeight(); j++) {
                    branchable.add(r);
                }
            } else {
                branchable.add(r);
            }
        }
        i++;
    }
}
Also used : MazeConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) SecretRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom) MazeConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom) ArrayList(java.util.ArrayList) MazeConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) ShopRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) SecretRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom) ExitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)

Example 7 with Room

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.

the class RingBridgeRoom method paint.

@Override
public void paint(Level level) {
    Painter.fill(level, this, 1, Terrain.CHASM);
    super.paint(level);
    for (Room r : neigbours) {
        if (r instanceof BridgeRoom || r instanceof RingBridgeRoom || r instanceof WalkwayRoom) {
            Rect i = intersect(r);
            if (i.width() != 0) {
                i.left++;
                i.right--;
            } else {
                i.top++;
                i.bottom--;
            }
            Painter.fill(level, i.left, i.top, i.width() + 1, i.height() + 1, Terrain.CHASM);
        }
    }
}
Also used : Rect(com.watabou.utils.Rect) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)

Example 8 with Room

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.

the class PrisonPainter method decorate.

@Override
protected void decorate(Level level, ArrayList<Room> rooms) {
    for (Room r : rooms) {
        if (r instanceof EntranceRoom) {
            Wandmaker.Quest.spawnWandmaker(level, r);
            break;
        }
    }
    int w = level.width();
    int l = level.length();
    int[] map = level.map;
    for (int i = w + 1; i < l - w - 1; i++) {
        if (map[i] == Terrain.EMPTY) {
            float c = 0.05f;
            if (map[i + 1] == Terrain.WALL && map[i + w] == Terrain.WALL) {
                c += 0.2f;
            }
            if (map[i - 1] == Terrain.WALL && map[i + w] == Terrain.WALL) {
                c += 0.2f;
            }
            if (map[i + 1] == Terrain.WALL && map[i - w] == Terrain.WALL) {
                c += 0.2f;
            }
            if (map[i - 1] == Terrain.WALL && map[i - w] == Terrain.WALL) {
                c += 0.2f;
            }
            if (Random.Float() < c) {
                map[i] = Terrain.EMPTY_DECO;
            }
        }
    }
    for (int i = 0; i < w; i++) {
        if (map[i] == Terrain.WALL && (map[i + w] == Terrain.EMPTY || map[i + w] == Terrain.EMPTY_SP) && Random.Int(6) == 0) {
            map[i] = Terrain.WALL_DECO;
        }
    }
    for (int i = w; i < l - w; i++) {
        if (map[i] == Terrain.WALL && map[i - w] == Terrain.WALL && (map[i + w] == Terrain.EMPTY || map[i + w] == Terrain.EMPTY_SP) && Random.Int(3) == 0) {
            map[i] = Terrain.WALL_DECO;
        }
    }
}
Also used : Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom)

Example 9 with Room

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.

the class RegularPainter method placeDoors.

private void placeDoors(Room r) {
    for (Room n : r.connected.keySet()) {
        Room.Door door = r.connected.get(n);
        if (door == null) {
            Rect i = r.intersect(n);
            ArrayList<Point> doorSpots = new ArrayList<>();
            for (Point p : i.getPoints()) {
                if (r.canConnect(p) && n.canConnect(p))
                    doorSpots.add(p);
            }
            if (doorSpots.isEmpty()) {
                ShatteredPixelDungeon.reportException(new RuntimeException("Could not place a door! " + "r=" + r.getClass().getSimpleName() + " n=" + n.getClass().getSimpleName()));
                continue;
            }
            door = new Room.Door(Random.element(doorSpots));
            r.connected.put(n, door);
            n.connected.put(r, door);
        }
    }
}
Also used : Rect(com.watabou.utils.Rect) ArrayList(java.util.ArrayList) Point(com.watabou.utils.Point) EmptyRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)

Example 10 with Room

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.

the class RegularPainter method paintTraps.

protected void paintTraps(Level l, ArrayList<Room> rooms) {
    ArrayList<Integer> validCells = new ArrayList<>();
    if (!rooms.isEmpty()) {
        for (Room r : rooms) {
            for (Point p : r.trapPlaceablePoints()) {
                int i = l.pointToCell(p);
                if (l.map[i] == Terrain.EMPTY) {
                    validCells.add(i);
                }
            }
        }
    } else {
        for (int i = 0; i < l.length(); i++) {
            if (l.map[i] == Terrain.EMPTY) {
                validCells.add(i);
            }
        }
    }
    // no more than one trap every 5 valid tiles.
    nTraps = Math.min(nTraps, validCells.size() / 5);
    for (int i = 0; i < nTraps; i++) {
        Integer trapPos = Random.element(validCells);
        // removes the integer object, not at the index
        validCells.remove(trapPos);
        try {
            Trap trap = trapClasses[Random.chances(trapChances)].newInstance().hide();
            l.setTrap(trap, trapPos);
            // some traps will not be hidden
            l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Trap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap) Point(com.watabou.utils.Point) EmptyRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) Point(com.watabou.utils.Point)

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