Search in sources :

Example 1 with Rect

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

the class RegularLevel 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);
            if (i.width() == 0) {
                door = new Room.Door(i.left, Random.Int(i.top + 1, i.bottom));
            } else {
                door = new Room.Door(Random.Int(i.left + 1, i.right), i.top);
            }
            r.connected.put(n, door);
            n.connected.put(r, door);
        }
    }
}
Also used : Rect(com.watabou.utils.Rect)

Example 2 with Rect

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

the class RegularLevel method split.

protected void split(Rect rect) {
    int w = rect.width();
    int h = rect.height();
    if (w > maxRoomSize && h < minRoomSize) {
        int vw = Random.Int(rect.left + 3, rect.right - 3);
        split(new Rect(rect.left, rect.top, vw, rect.bottom));
        split(new Rect(vw, rect.top, rect.right, rect.bottom));
    } else if (h > maxRoomSize && w < minRoomSize) {
        int vh = Random.Int(rect.top + 3, rect.bottom - 3);
        split(new Rect(rect.left, rect.top, rect.right, vh));
        split(new Rect(rect.left, vh, rect.right, rect.bottom));
    } else if ((Math.random() <= (minRoomSize * minRoomSize / rect.square()) && w <= maxRoomSize && h <= maxRoomSize) || w < minRoomSize || h < minRoomSize) {
        rooms.add((Room) new Room().set(rect));
    } else {
        if (Random.Float() < (float) (w - 2) / (w + h - 4)) {
            int vw = Random.Int(rect.left + 3, rect.right - 3);
            split(new Rect(rect.left, rect.top, vw, rect.bottom));
            split(new Rect(vw, rect.top, rect.right, rect.bottom));
        } else {
            int vh = Random.Int(rect.top + 3, rect.bottom - 3);
            split(new Rect(rect.left, rect.top, rect.right, vh));
            split(new Rect(rect.left, vh, rect.right, rect.bottom));
        }
    }
}
Also used : Rect(com.watabou.utils.Rect)

Example 3 with Rect

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

the class CavesLevel method decorate.

@Override
protected void decorate() {
    for (Room room : rooms) {
        if (room.type != Room.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) * WIDTH;
            if (map[corner - 1] == Terrain.WALL && map[corner - WIDTH] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.right - 1) + (room.top + 1) * WIDTH;
            if (map[corner + 1] == Terrain.WALL && map[corner - WIDTH] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.left + 1) + (room.bottom - 1) * WIDTH;
            if (map[corner - 1] == Terrain.WALL && map[corner + WIDTH] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.right - 1) + (room.bottom - 1) * WIDTH;
            if (map[corner + 1] == Terrain.WALL && map[corner + WIDTH] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
            }
        }
        for (Room n : room.connected.keySet()) {
            if ((n.type == Room.Type.STANDARD || n.type == Room.Type.TUNNEL) && Random.Int(3) == 0) {
                Painter.set(this, room.connected.get(n), Terrain.EMPTY_DECO);
            }
        }
    }
    for (int i = WIDTH + 1; i < LENGTH - WIDTH; 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 + WIDTH] == Terrain.WALL) {
                n++;
            }
            if (map[i - WIDTH] == Terrain.WALL) {
                n++;
            }
            if (Random.Int(6) <= n) {
                map[i] = Terrain.EMPTY_DECO;
            }
        }
    }
    for (int i = 0; i < LENGTH; i++) {
        if (map[i] == Terrain.WALL && Random.Int(12) == 0) {
            map[i] = Terrain.WALL_DECO;
        }
    }
    while (true) {
        int pos = roomEntrance.random();
        if (pos != entrance) {
            map[pos] = Terrain.SIGN;
            break;
        }
    }
    if (Dungeon.bossLevel(Dungeon.depth + 1)) {
        return;
    }
    for (Room r : rooms) {
        if (r.type == Type.STANDARD) {
            for (Room n : r.neigbours) {
                if (n.type == Type.STANDARD && !r.connected.containsKey(n)) {
                    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)

Example 4 with Rect

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

the class RegularLevel method joinRooms.

protected boolean joinRooms(Room r, Room n) {
    if (r.type != Room.Type.STANDARD || n.type != Room.Type.STANDARD) {
        return false;
    }
    Rect w = r.intersect(n);
    if (w.left == w.right) {
        if (w.bottom - w.top < 3) {
            return false;
        }
        if (w.height() == Math.max(r.height(), n.height())) {
            return false;
        }
        if (r.width() + n.width() > maxRoomSize) {
            return false;
        }
        w.top += 1;
        w.bottom -= 0;
        w.right++;
        Painter.fill(this, w.left, w.top, 1, w.height(), Terrain.EMPTY);
    } else {
        if (w.right - w.left < 3) {
            return false;
        }
        if (w.width() == Math.max(r.width(), n.width())) {
            return false;
        }
        if (r.height() + n.height() > maxRoomSize) {
            return false;
        }
        w.left += 1;
        w.right -= 0;
        w.bottom++;
        Painter.fill(this, w.left, w.top, w.width(), 1, Terrain.EMPTY);
    }
    return true;
}
Also used : Rect(com.watabou.utils.Rect)

Example 5 with Rect

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

the class RegularLevel method initRooms.

protected boolean initRooms() {
    rooms = new HashSet<Room>();
    split(new Rect(0, 0, WIDTH - 1, HEIGHT - 1));
    if (rooms.size() < 8) {
        return false;
    }
    Room[] ra = rooms.toArray(new Room[0]);
    for (int i = 0; i < ra.length - 1; i++) {
        for (int j = i + 1; j < ra.length; j++) {
            ra[i].addNeigbour(ra[j]);
        }
    }
    return true;
}
Also used : Rect(com.watabou.utils.Rect)

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