use of com.watabou.utils.Rect in project shattered-pixel-dungeon-gdx by 00-Evan.
the class SegmentedRoom method paint.
@Override
public void paint(Level level) {
Painter.fill(level, this, Terrain.WALL);
Painter.fill(level, this, 1, Terrain.EMPTY);
for (Door door : connected.values()) {
door.set(Door.Type.REGULAR);
// set door areas to be empty to help with create walls logic
Painter.set(level, door, Terrain.EMPTY);
}
createWalls(level, new Rect(left + 1, top + 1, right - 1, bottom - 1));
}
use of com.watabou.utils.Rect in project shattered-pixel-dungeon-gdx by 00-Evan.
the class FogOfWar method updateTexture.
private void updateTexture(boolean[] visible, boolean[] visited, boolean[] mapped) {
this.visible = visible;
this.visited = visited;
this.mapped = mapped;
this.brightness = SPDSettings.brightness() + 2;
moveToUpdating();
boolean fullUpdate = false;
if (updating.size() == 1) {
Rect update = updating.get(0);
if (update.height() == mapHeight && update.width() == mapWidth) {
fullUpdate = true;
}
}
BufferTexture fog = (BufferTexture) texture;
int cell;
for (Rect update : updating) {
for (int i = update.top; i <= update.bottom; i++) {
cell = mapWidth * i + update.left;
for (int j = update.left; j <= update.right; j++) {
// do nothing
if (cell >= Dungeon.level.length())
continue;
if (!Dungeon.level.discoverable[cell] || (!visible[cell] && !visited[cell] && !mapped[cell])) {
// because they must already be dark
if (fullUpdate)
fillCell(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
cell++;
continue;
}
// wall tiles
if (wall(cell)) {
// always dark if nothing is beneath them
if (cell + mapWidth >= mapLength) {
fillCell(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
// internal wall tiles, need to check both the left and right side,
// to account for only one half of them being seen
} else if (wall(cell + mapWidth)) {
// left side
if (cell % mapWidth != 0) {
// picks the darkest fog between current tile, left, and below-left(if left is a wall).
if (wall(cell - 1)) {
// if below-left is also a wall, then we should be dark no matter what.
if (wall(cell + mapWidth - 1)) {
fillLeft(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
} else {
fillLeft(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), Math.max(getCellFog(cell + mapWidth - 1), getCellFog(cell - 1)))][brightness]);
}
} else {
fillLeft(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell - 1))][brightness]);
}
} else {
fillLeft(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
}
// right side
if ((cell + 1) % mapWidth != 0) {
// picks the darkest fog between current tile, right, and below-right(if right is a wall).
if (wall(cell + 1)) {
// if below-right is also a wall, then we should be dark no matter what.
if (wall(cell + mapWidth + 1)) {
fillRight(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
} else {
fillRight(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), Math.max(getCellFog(cell + mapWidth + 1), getCellFog(cell + 1)))][brightness]);
}
} else {
fillRight(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell + 1))][brightness]);
}
} else {
fillRight(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
}
// camera-facing wall tiles
// darkest between themselves and the tile below them
} else {
fillCell(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell + mapWidth))][brightness]);
}
// other tiles, just their direct value
} else {
fillCell(fog, j, i, FOG_COLORS[getCellFog(cell)][brightness]);
}
cell++;
}
}
}
if (updating.size() == 1 && !fullUpdate) {
fog.update(updating.get(0).top * PIX_PER_TILE, updating.get(0).bottom * PIX_PER_TILE);
} else {
fog.update();
}
}
use of com.watabou.utils.Rect in project shattered-pixel-dungeon-gdx by 00-Evan.
the class FogOfWar method updateFog.
public synchronized void updateFog() {
toUpdate.clear();
toUpdate.add(new Rect(0, 0, mapWidth, mapHeight));
}
use of com.watabou.utils.Rect in project pixel-dungeon-remix by NYRDS.
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);
}
}
}
use of com.watabou.utils.Rect in project pixel-dungeon-remix by NYRDS.
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));
}
}
}
Aggregations