Search in sources :

Example 26 with Room

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

the class BridgeRoom method paint.

@Override
public void paint(Level level) {
    if (Math.min(width(), height()) > 3) {
        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 27 with Room

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

the class Builder method findFreeSpace.

// returns a rectangle representing the maximum amount of free space from a specific start point
protected static Rect findFreeSpace(Point start, ArrayList<Room> collision, int maxSize) {
    Rect space = new Rect(start.x - maxSize, start.y - maxSize, start.x + maxSize, start.y + maxSize);
    // shallow copy
    ArrayList<Room> colliding = new ArrayList<>(collision);
    do {
        // remove empty rooms and any rooms we aren't currently overlapping
        Iterator<Room> it = colliding.iterator();
        while (it.hasNext()) {
            Room room = it.next();
            // if not colliding
            if (room.isEmpty() || Math.max(space.left, room.left) >= Math.min(space.right, room.right) || Math.max(space.top, room.top) >= Math.min(space.bottom, room.bottom)) {
                it.remove();
            }
        }
        // iterate through all rooms we are overlapping, and find the closest one
        Room closestRoom = null;
        int closestDiff = Integer.MAX_VALUE;
        boolean inside = true;
        int curDiff = 0;
        for (Room curRoom : colliding) {
            if (start.x <= curRoom.left) {
                inside = false;
                curDiff += curRoom.left - start.x;
            } else if (start.x >= curRoom.right) {
                inside = false;
                curDiff += start.x - curRoom.right;
            }
            if (start.y <= curRoom.top) {
                inside = false;
                curDiff += curRoom.top - start.y;
            } else if (start.y >= curRoom.bottom) {
                inside = false;
                curDiff += start.y - curRoom.bottom;
            }
            if (inside) {
                space.set(start.x, start.y, start.x, start.y);
                return space;
            }
            if (curDiff < closestDiff) {
                closestDiff = curDiff;
                closestRoom = curRoom;
            }
        }
        int wDiff, hDiff;
        if (closestRoom != null) {
            wDiff = Integer.MAX_VALUE;
            if (closestRoom.left >= start.x) {
                wDiff = (space.right - closestRoom.left) * (space.height() + 1);
            } else if (closestRoom.right <= start.x) {
                wDiff = (closestRoom.right - space.left) * (space.height() + 1);
            }
            hDiff = Integer.MAX_VALUE;
            if (closestRoom.top >= start.y) {
                hDiff = (space.bottom - closestRoom.top) * (space.width() + 1);
            } else if (closestRoom.bottom <= start.y) {
                hDiff = (closestRoom.bottom - space.top) * (space.width() + 1);
            }
            // reduce by as little as possible to resolve the collision
            if (wDiff < hDiff || wDiff == hDiff && Random.Int(2) == 0) {
                if (closestRoom.left >= start.x && closestRoom.left < space.right)
                    space.right = closestRoom.left;
                if (closestRoom.right <= start.x && closestRoom.right > space.left)
                    space.left = closestRoom.right;
            } else {
                if (closestRoom.top >= start.y && closestRoom.top < space.bottom)
                    space.bottom = closestRoom.top;
                if (closestRoom.bottom <= start.y && closestRoom.bottom > space.top)
                    space.top = closestRoom.bottom;
            }
            colliding.remove(closestRoom);
        } else {
            colliding.clear();
        }
    // loop until we are no longer colliding with any rooms
    } while (!colliding.isEmpty());
    return space;
}
Also used : Rect(com.watabou.utils.Rect) ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) Point(com.watabou.utils.Point)

Example 28 with Room

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

the class RockfallTrap method activate.

@Override
public void activate() {
    ArrayList<Integer> rockCells = new ArrayList<>();
    if (Dungeon.level instanceof RegularLevel) {
        Room r = ((RegularLevel) Dungeon.level).room(pos);
        int cell;
        for (Point p : r.getPoints()) {
            cell = Dungeon.level.pointToCell(p);
            if (!Dungeon.level.solid[cell]) {
                rockCells.add(cell);
            }
        }
    // if we don't have rooms, then just do 5x5
    } else {
        PathFinder.buildDistanceMap(pos, BArray.not(Dungeon.level.solid, null), 2);
        for (int i = 0; i < PathFinder.distance.length; i++) {
            if (PathFinder.distance[i] < Integer.MAX_VALUE) {
                rockCells.add(i);
            }
        }
    }
    boolean seen = false;
    for (int cell : rockCells) {
        if (Dungeon.level.heroFOV[cell]) {
            CellEmitter.get(cell - Dungeon.level.width()).start(Speck.factory(Speck.ROCK), 0.07f, 10);
            seen = true;
        }
        Char ch = Actor.findChar(cell);
        if (ch != null) {
            int damage = Random.NormalIntRange(5 + Dungeon.depth, 10 + Dungeon.depth * 2);
            damage -= ch.drRoll();
            ch.damage(Math.max(damage, 0), this);
            Buff.prolong(ch, Paralysis.class, Paralysis.DURATION);
            if (!ch.isAlive() && ch == Dungeon.hero) {
                Dungeon.fail(getClass());
                GLog.n(Messages.get(this, "ondeath"));
            }
        }
    }
    if (seen) {
        Camera.main.shake(3, 0.7f);
        Sample.INSTANCE.play(Assets.SND_ROCKS);
    }
}
Also used : Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) ArrayList(java.util.ArrayList) Point(com.watabou.utils.Point) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) Point(com.watabou.utils.Point) RegularLevel(com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel)

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