Search in sources :

Example 31 with Rect

use of com.watabou.utils.Rect 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 32 with Rect

use of com.watabou.utils.Rect 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 33 with Rect

use of com.watabou.utils.Rect in project shattered-pixel-dungeon-gdx by 00-Evan.

the class FogOfWar method updateFog.

public synchronized void updateFog(Rect update) {
    for (Rect r : toUpdate.toArray(new Rect[0])) {
        if (!r.intersect(update).isEmpty()) {
            toUpdate.remove(r);
            toUpdate.add(r.union(update));
            return;
        }
    }
    toUpdate.add(update);
}
Also used : Rect(com.watabou.utils.Rect)

Example 34 with Rect

use of com.watabou.utils.Rect in project shattered-pixel-dungeon-gdx by 00-Evan.

the class FogOfWar method updateFog.

public synchronized void updateFog(int cell, int radius) {
    Rect update = new Rect((cell % mapWidth) - radius, (cell / mapWidth) - radius, (cell % mapWidth) - radius + 1 + 2 * radius, (cell / mapWidth) - radius + 1 + 2 * radius);
    update.left = Math.max(0, update.left);
    update.top = Math.max(0, update.top);
    update.right = Math.min(mapWidth, update.right);
    update.bottom = Math.min(mapHeight, update.bottom);
    if (update.isEmpty())
        return;
    updateFog(update);
}
Also used : Rect(com.watabou.utils.Rect)

Example 35 with Rect

use of com.watabou.utils.Rect in project pixel-dungeon-remix by NYRDS.

the class IceCavesLevel method decorate.

@Override
protected void decorate() {
    for (Room room : rooms) {
        if (room.type != Type.STANDARD) {
            continue;
        }
        if (room.width() <= 3 || room.height() <= 3) {
            continue;
        }
        int s = room.square();
        if (Random.Int(s) > 8) {
            int corner = (room.left + 1) + (room.top + 1) * getWidth();
            if (map[corner - 1] == Terrain.WALL && map[corner - getWidth()] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.right - 1) + (room.top + 1) * getWidth();
            if (map[corner + 1] == Terrain.WALL && map[corner - getWidth()] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.left + 1) + (room.bottom - 1) * getWidth();
            if (map[corner - 1] == Terrain.WALL && map[corner + getWidth()] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.right - 1) + (room.bottom - 1) * getWidth();
            if (map[corner + 1] == Terrain.WALL && map[corner + getWidth()] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        for (Room n : room.connected.keySet()) {
            if ((n.type == Type.STANDARD || n.type == Type.TUNNEL) && Random.Int(3) == 0) {
                Painter.set(this, room.connected.get(n), Terrain.EMPTY_DECO);
            }
        }
    }
    for (int i = getWidth() + 1; i < getLength() - getWidth(); 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 + getWidth()] == Terrain.WALL) {
                n++;
            }
            if (map[i - getWidth()] == Terrain.WALL) {
                n++;
            }
            if (Random.Int(6) <= n) {
                map[i] = Terrain.EMPTY_DECO;
            }
        }
    }
    for (int i = 0; i < getLength(); i++) {
        if (map[i] == Terrain.WALL && Random.Int(12) == 0) {
            map[i] = Terrain.WALL_DECO;
        }
    }
    for (Room r : rooms) {
        if (r.type == Type.STANDARD) {
            for (Room n : r.neighbours) {
                if (n.type == Type.STANDARD && !r.connected.containsKey(n)) /* && Random.Int( 2 ) == 0*/
                {
                    Rect w = r.intersect(n);
                    if (w.left == w.right && w.bottom - w.top >= 5) {
                        w.top += 2;
                        w.bottom -= 1;
                        w.right++;
                        Painter.fill(this, w.left, w.top, 1, w.height(), Terrain.CHASM);
                    } else if (w.top == w.bottom && w.right - w.left >= 5) {
                        w.left += 2;
                        w.right -= 1;
                        w.bottom++;
                        Painter.fill(this, w.left, w.top, w.width(), 1, Terrain.CHASM);
                    }
                }
            }
        }
    }
}
Also used : Rect(com.watabou.utils.Rect) Room(com.watabou.pixeldungeon.levels.Room)

Aggregations

Rect (com.watabou.utils.Rect)38 Point (com.watabou.utils.Point)10 Room (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)6 ArrayList (java.util.ArrayList)4 EmptyRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom)3 ConnectionRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)1 CaveRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.CaveRoom)1 StandardRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)1 ToxicTrap (com.shatteredpixel.shatteredpixeldungeon.levels.traps.ToxicTrap)1 Trap (com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap)1 BufferTexture (com.watabou.gltextures.BufferTexture)1 Room (com.watabou.pixeldungeon.levels.Room)1 PointF (com.watabou.utils.PointF)1