Java Code Examples for com.watabou.utils.Rect#set()
The following examples show how to use
com.watabou.utils.Rect#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OldCavesBossLevel.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override protected boolean build() { setSize(WIDTH, HEIGHT); Rect space = new Rect(); space.set( Random.IntRange(2, 6), Random.IntRange(2, 6), Random.IntRange(width-6, width-2), Random.IntRange(height-6, height-2) ); Painter.fillEllipse( this, space, Terrain.EMPTY ); exit = space.left + space.width()/2 + (space.top - 1) * width(); map[exit] = Terrain.LOCKED_EXIT; Painter.fill( this, ROOM_LEFT - 1, ROOM_TOP - 1, ROOM_RIGHT - ROOM_LEFT + 3, ROOM_BOTTOM - ROOM_TOP + 3, Terrain.WALL ); Painter.fill( this, ROOM_LEFT, ROOM_TOP + 1, ROOM_RIGHT - ROOM_LEFT + 1, ROOM_BOTTOM - ROOM_TOP, Terrain.EMPTY ); Painter.fill( this, ROOM_LEFT, ROOM_TOP, ROOM_RIGHT - ROOM_LEFT + 1, 1, Terrain.EMPTY_DECO ); arenaDoor = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + (ROOM_BOTTOM + 1) * width(); map[arenaDoor] = Terrain.DOOR; entrance = Random.Int( ROOM_LEFT + 1, ROOM_RIGHT - 1 ) + Random.Int( ROOM_TOP + 1, ROOM_BOTTOM - 1 ) * width(); map[entrance] = Terrain.ENTRANCE; boolean[] patch = Patch.generate( width, height, 0.30f, 6, true ); for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && patch[i]) { map[i] = Terrain.WATER; } } for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 6 ) == 0) { map[i] = Terrain.INACTIVE_TRAP; Trap t = new ToxicTrap().reveal(); t.active = false; setTrap(t, i); } } 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( 8 ) <= n) { map[i] = Terrain.EMPTY_DECO; } } } for (int i=0; i < length() - width(); i++) { if (map[i] == Terrain.WALL && DungeonTileSheet.floorTile(map[i + width()]) && Random.Int( 3 ) == 0) { map[i] = Terrain.WALL_DECO; } } return true; }
Example 2
Source File: Builder.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
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; }
Example 3
Source File: CavesBossLevel.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
@Override protected boolean build() { setSize(WIDTH, HEIGHT); Rect space = new Rect(); space.set( Random.IntRange(2, 6), Random.IntRange(2, 6), Random.IntRange(width-6, width-2), Random.IntRange(height-6, height-2) ); Painter.fillEllipse( this, space, Terrain.EMPTY ); exit = space.left + space.width()/2 + (space.top - 1) * width(); map[exit] = Terrain.LOCKED_EXIT; Painter.fill( this, ROOM_LEFT - 1, ROOM_TOP - 1, ROOM_RIGHT - ROOM_LEFT + 3, ROOM_BOTTOM - ROOM_TOP + 3, Terrain.WALL ); Painter.fill( this, ROOM_LEFT, ROOM_TOP + 1, ROOM_RIGHT - ROOM_LEFT + 1, ROOM_BOTTOM - ROOM_TOP, Terrain.EMPTY ); Painter.fill( this, ROOM_LEFT, ROOM_TOP, ROOM_RIGHT - ROOM_LEFT + 1, 1, Terrain.EMPTY_DECO ); arenaDoor = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + (ROOM_BOTTOM + 1) * width(); map[arenaDoor] = Terrain.DOOR; entrance = Random.Int( ROOM_LEFT + 1, ROOM_RIGHT - 1 ) + Random.Int( ROOM_TOP + 1, ROOM_BOTTOM - 1 ) * width(); map[entrance] = Terrain.ENTRANCE; boolean[] patch = Patch.generate( width, height, 0.30f, 6, true ); for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && patch[i]) { map[i] = Terrain.WATER; } } for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 6 ) == 0) { map[i] = Terrain.INACTIVE_TRAP; Trap t = new ToxicTrap().reveal(); t.active = false; setTrap(t, i); } } 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( 8 ) <= n) { map[i] = Terrain.EMPTY_DECO; } } } for (int i=0; i < length() - width(); i++) { if (map[i] == Terrain.WALL && DungeonTileSheet.floorTile(map[i + width()]) && Random.Int( 3 ) == 0) { map[i] = Terrain.WALL_DECO; } } return true; }
Example 4
Source File: Builder.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
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; }