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);
}
}
}
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;
}
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);
}
}
Aggregations