Search in sources :

Example 26 with Rect

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

the class RingTunnelRoom method getConnectionSpace.

@Override
protected Rect getConnectionSpace() {
    if (connSpace == null) {
        Point c = getDoorCenter();
        c.x = (int) GameMath.gate(left + 2, c.x, right - 2);
        c.y = (int) GameMath.gate(top + 2, c.y, bottom - 2);
        connSpace = new Rect(c.x - 1, c.y - 1, c.x + 1, c.y + 1);
    }
    return connSpace;
}
Also used : Rect(com.watabou.utils.Rect) Point(com.watabou.utils.Point)

Example 27 with Rect

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

the class HallwayRoom method paint.

// FIXME lots of copy-pasta from tunnel rooms here
@Override
public void paint(Level level) {
    Painter.fill(level, this, Terrain.WALL);
    Painter.fill(level, this, 1, Terrain.EMPTY);
    if (connected.size() < 2) {
        // don't want to make a hallway between doors that don't exist
        return;
    }
    Rect c = getConnectionSpace();
    for (Door door : connected.values()) {
        Point start;
        Point mid;
        Point end;
        start = new Point(door);
        if (start.x == left)
            start.x++;
        else if (start.y == top)
            start.y++;
        else if (start.x == right)
            start.x--;
        else if (start.y == bottom)
            start.y--;
        int rightShift;
        int downShift;
        if (start.x < c.left)
            rightShift = c.left - start.x;
        else if (start.x > c.right)
            rightShift = c.right - start.x;
        else
            rightShift = 0;
        if (start.y < c.top)
            downShift = c.top - start.y;
        else if (start.y > c.bottom)
            downShift = c.bottom - start.y;
        else
            downShift = 0;
        // always goes inward first
        if (door.x == left || door.x == right) {
            mid = new Point(start.x + rightShift, start.y);
            end = new Point(mid.x, mid.y + downShift);
        } else {
            mid = new Point(start.x, start.y + downShift);
            end = new Point(mid.x + rightShift, mid.y);
        }
        Painter.drawLine(level, start, mid, Terrain.EMPTY_SP);
        Painter.drawLine(level, mid, end, Terrain.EMPTY_SP);
    }
    for (Door door : connected.values()) {
        door.set(Door.Type.REGULAR);
    }
}
Also used : Rect(com.watabou.utils.Rect) Point(com.watabou.utils.Point) Point(com.watabou.utils.Point)

Example 28 with Rect

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

the class SegmentedRoom method createWalls.

private void createWalls(Level level, Rect area) {
    if (Math.max(area.width() + 1, area.height() + 1) < 5 || Math.min(area.width() + 1, area.height() + 1) < 3) {
        return;
    }
    int tries = 10;
    // splitting top/bottom
    if (area.width() > area.height() || (area.width() == area.height() && Random.Int(2) == 0)) {
        do {
            int splitX = Random.IntRange(area.left + 2, area.right - 2);
            if (level.map[splitX + level.width() * (area.top - 1)] == Terrain.WALL && level.map[splitX + level.width() * (area.bottom + 1)] == Terrain.WALL) {
                tries = 0;
                Painter.drawLine(level, new Point(splitX, area.top), new Point(splitX, area.bottom), Terrain.WALL);
                int spaceTop = Random.IntRange(area.top, area.bottom - 1);
                Painter.set(level, splitX, spaceTop, Terrain.EMPTY);
                Painter.set(level, splitX, spaceTop + 1, Terrain.EMPTY);
                createWalls(level, new Rect(area.left, area.top, splitX - 1, area.bottom));
                createWalls(level, new Rect(splitX + 1, area.top, area.right, area.bottom));
            }
        } while (--tries > 0);
    // splitting left/right
    } else {
        do {
            int splitY = Random.IntRange(area.top + 2, area.bottom - 2);
            if (level.map[area.left - 1 + level.width() * splitY] == Terrain.WALL && level.map[area.right + 1 + level.width() * splitY] == Terrain.WALL) {
                tries = 0;
                Painter.drawLine(level, new Point(area.left, splitY), new Point(area.right, splitY), Terrain.WALL);
                int spaceLeft = Random.IntRange(area.left, area.right - 1);
                Painter.set(level, spaceLeft, splitY, Terrain.EMPTY);
                Painter.set(level, spaceLeft + 1, splitY, Terrain.EMPTY);
                createWalls(level, new Rect(area.left, area.top, area.right, splitY - 1));
                createWalls(level, new Rect(area.left, splitY + 1, area.right, area.bottom));
            }
        } while (--tries > 0);
    }
}
Also used : Rect(com.watabou.utils.Rect) Point(com.watabou.utils.Point) Point(com.watabou.utils.Point)

Example 29 with Rect

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

the class SewerPipeRoom method paint.

// FIXME this class is a total mess, lots of copy-pasta from tunnel and perimeter rooms here
@Override
public void paint(Level level) {
    Painter.fill(level, this, Terrain.WALL);
    Rect c = getConnectionSpace();
    if (connected.size() <= 2) {
        for (Door door : connected.values()) {
            Point start;
            Point mid;
            Point end;
            start = new Point(door);
            if (start.x == left)
                start.x += 2;
            else if (start.y == top)
                start.y += 2;
            else if (start.x == right)
                start.x -= 2;
            else if (start.y == bottom)
                start.y -= 2;
            int rightShift;
            int downShift;
            if (start.x < c.left)
                rightShift = c.left - start.x;
            else if (start.x > c.right)
                rightShift = c.right - start.x;
            else
                rightShift = 0;
            if (start.y < c.top)
                downShift = c.top - start.y;
            else if (start.y > c.bottom)
                downShift = c.bottom - start.y;
            else
                downShift = 0;
            // always goes inward first
            if (door.x == left || door.x == right) {
                mid = new Point(start.x + rightShift, start.y);
                end = new Point(mid.x, mid.y + downShift);
            } else {
                mid = new Point(start.x, start.y + downShift);
                end = new Point(mid.x + rightShift, mid.y);
            }
            Painter.drawLine(level, start, mid, Terrain.WATER);
            Painter.drawLine(level, mid, end, Terrain.WATER);
        }
    } else {
        ArrayList<Point> pointsToFill = new ArrayList<>();
        for (Point door : connected.values()) {
            Point p = new Point(door);
            if (p.y == top) {
                p.y += 2;
            } else if (p.y == bottom) {
                p.y -= 2;
            } else if (p.x == left) {
                p.x += 2;
            } else {
                p.x -= 2;
            }
            pointsToFill.add(p);
        }
        ArrayList<Point> pointsFilled = new ArrayList<>();
        pointsFilled.add(pointsToFill.remove(0));
        Point from = null, to = null;
        int shortestDistance;
        while (!pointsToFill.isEmpty()) {
            shortestDistance = Integer.MAX_VALUE;
            for (Point f : pointsFilled) {
                for (Point t : pointsToFill) {
                    int dist = distanceBetweenPoints(f, t);
                    if (dist < shortestDistance) {
                        from = f;
                        to = t;
                        shortestDistance = dist;
                    }
                }
            }
            fillBetweenPoints(level, from, to, Terrain.WATER);
            pointsFilled.add(to);
            pointsToFill.remove(to);
        }
    }
    for (Point p : getPoints()) {
        int cell = level.pointToCell(p);
        if (level.map[cell] == Terrain.WATER) {
            for (int i : PathFinder.NEIGHBOURS8) {
                if (level.map[cell + i] == Terrain.WALL) {
                    Painter.set(level, cell + i, Terrain.EMPTY);
                }
            }
        }
    }
    for (Door door : connected.values()) {
        door.set(Door.Type.REGULAR);
    }
}
Also used : Rect(com.watabou.utils.Rect) ArrayList(java.util.ArrayList) Point(com.watabou.utils.Point) Point(com.watabou.utils.Point)

Example 30 with Rect

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

the class RegularPainter method joinRooms.

protected boolean joinRooms(Level l, Room r, Room n) {
    if (!(r instanceof EmptyRoom && n instanceof EmptyRoom)) {
        return false;
    }
    // TODO decide on good probabilities and dimension restrictions
    Rect w = r.intersect(n);
    if (w.left == w.right) {
        if (w.bottom - w.top < 3) {
            return false;
        }
        if (w.height() + 1 == Math.max(r.height(), n.height())) {
            return false;
        }
        if (r.width() + n.width() > 10) {
            return false;
        }
        w.top += 1;
        w.bottom -= 0;
        w.right++;
        Painter.fill(l, w.left, w.top, 1, w.height(), Terrain.EMPTY);
    } else {
        if (w.right - w.left < 3) {
            return false;
        }
        if (w.width() + 1 == Math.max(r.width(), n.width())) {
            return false;
        }
        if (r.height() + n.height() > 10) {
            return false;
        }
        w.left += 1;
        w.right -= 0;
        w.bottom++;
        Painter.fill(l, w.left, w.top, w.width(), 1, Terrain.EMPTY);
    }
    return true;
}
Also used : Rect(com.watabou.utils.Rect) EmptyRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom)

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