Java Code Examples for com.watabou.utils.Rect#height()

The following examples show how to use com.watabou.utils.Rect#height() . 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: Room.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public boolean canConnect( Room r ){
	Rect i = intersect( r );
	
	boolean foundPoint = false;
	for (Point p : i.getPoints()){
		if (canConnect(p) && r.canConnect(p)){
			foundPoint = true;
			break;
		}
	}
	if (!foundPoint) return false;
	
	if (i.width() == 0 && i.left == left)
		return canConnect(LEFT) && r.canConnect(LEFT);
	else if (i.height() == 0 && i.top == top)
		return canConnect(TOP) && r.canConnect(TOP);
	else if (i.width() == 0 && i.right == right)
		return canConnect(RIGHT) && r.canConnect(RIGHT);
	else if (i.height() == 0 && i.bottom == bottom)
		return canConnect(BOTTOM) && r.canConnect(BOTTOM);
	else
		return false;
}
 
Example 2
Source File: Room.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public int curConnections(int direction){
	if (direction == ALL) {
		return connected.size();
		
	} else {
		int total = 0;
		for (Room r : connected.keySet()){
			Rect i = intersect( r );
			if      (direction == LEFT && i.width() == 0 && i.left == left)         total++;
			else if (direction == TOP && i.height() == 0 && i.top == top)           total++;
			else if (direction == RIGHT && i.width() == 0 && i.right == right)      total++;
			else if (direction == BOTTOM && i.height() == 0 && i.bottom == bottom)  total++;
		}
		return total;
	}
}
 
Example 3
Source File: PlatformRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
private void splitPlatforms( Rect curPlatform, ArrayList<Rect> allPlatforms ){
	int curArea = (curPlatform.width()+1) * (curPlatform.height()+1);
	
	//chance to split scales between 0% and 100% between areas of 25 and 36
	if (Random.Float() < (curArea-25)/11f){
		if (curPlatform.width() > curPlatform.height() ||
				(curPlatform.width() == curPlatform.height() && Random.Int(2) == 0)){
			
			//split the platform
			int splitX = Random.IntRange( curPlatform.left+2, curPlatform.right-2);
			splitPlatforms( new Rect( curPlatform.left, curPlatform.top, splitX-1, curPlatform.bottom) , allPlatforms);
			splitPlatforms( new Rect( splitX+1, curPlatform.top, curPlatform.right, curPlatform.bottom) , allPlatforms);
			
			//add a bridge between
			int bridgeY = Random.NormalIntRange(curPlatform.top, curPlatform.bottom);
			allPlatforms.add( new Rect( splitX - 1, bridgeY, splitX + 1, bridgeY));
			
		} else {
			
			//split the platform
			int splitY = Random.IntRange( curPlatform.top+2, curPlatform.bottom-2);
			splitPlatforms( new Rect( curPlatform.left, curPlatform.top, curPlatform.right, splitY-1) , allPlatforms);
			splitPlatforms( new Rect( curPlatform.left, splitY+1, curPlatform.right, curPlatform.bottom) , allPlatforms);
			
			//add a bridge between
			int bridgeX = Random.NormalIntRange(curPlatform.left, curPlatform.right);
			allPlatforms.add( new Rect( bridgeX, splitY-1, bridgeX, splitY+1));
			
		}
	} else {
		allPlatforms.add(curPlatform);
	}
}
 
Example 4
Source File: Maze.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public static boolean[][] generate(Rect r, int[] terrain, int width, int filledTerrainType){
	boolean[][] maze = new boolean[r.width()][r.height()];
	for (int x = 0; x < maze.length; x++) {
		for (int y = 0; y < maze[0].length; y++) {
			if (terrain[x + r.left + (y + r.top)*width] == filledTerrainType){
				maze[x][y] = FILLED;
			}
		}
	}
	
	return generate(maze);
}
 
Example 5
Source File: Room.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public boolean addNeigbour( Room other ) {
	if (neigbours.contains(other))
		return true;
	
	Rect i = intersect( other );
	if ((i.width() == 0 && i.height() >= 2) ||
		(i.height() == 0 && i.width() >= 2)) {
		neigbours.add( other );
		other.neigbours.add( this );
		return true;
	}
	return false;
}
 
Example 6
Source File: PlatformRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private void splitPlatforms( Rect curPlatform, ArrayList<Rect> allPlatforms ){
	int curArea = (curPlatform.width()+1) * (curPlatform.height()+1);
	
	//chance to split scales between 0% and 100% between areas of 25 and 36
	if (Random.Float() < (curArea-25)/11f){
		if (curPlatform.width() > curPlatform.height() ||
				(curPlatform.width() == curPlatform.height() && Random.Int(2) == 0)){
			
			//split the platform
			int splitX = Random.IntRange( curPlatform.left+2, curPlatform.right-2);
			splitPlatforms( new Rect( curPlatform.left, curPlatform.top, splitX-1, curPlatform.bottom) , allPlatforms);
			splitPlatforms( new Rect( splitX+1, curPlatform.top, curPlatform.right, curPlatform.bottom) , allPlatforms);
			
			//add a bridge between
			int bridgeY = Random.NormalIntRange(curPlatform.top, curPlatform.bottom);
			allPlatforms.add( new Rect( splitX - 1, bridgeY, splitX + 1, bridgeY));
			
		} else {
			
			//split the platform
			int splitY = Random.IntRange( curPlatform.top+2, curPlatform.bottom-2);
			splitPlatforms( new Rect( curPlatform.left, curPlatform.top, curPlatform.right, splitY-1) , allPlatforms);
			splitPlatforms( new Rect( curPlatform.left, splitY+1, curPlatform.right, curPlatform.bottom) , allPlatforms);
			
			//add a bridge between
			int bridgeX = Random.NormalIntRange(curPlatform.left, curPlatform.right);
			allPlatforms.add( new Rect( bridgeX, splitY-1, bridgeX, splitY+1));
			
		}
	} else {
		allPlatforms.add(curPlatform);
	}
}
 
Example 7
Source File: Maze.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static boolean[][] generate(Rect r, int[] terrain, int width, int filledTerrainType){
	boolean[][] maze = new boolean[r.width()][r.height()];
	for (int x = 0; x < maze.length; x++) {
		for (int y = 0; y < maze[0].length; y++) {
			if (terrain[x + r.left + (y + r.top)*width] == filledTerrainType){
				maze[x][y] = FILLED;
			}
		}
	}
	
	return generate(maze);
}
 
Example 8
Source File: Room.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void addNeigbour( Room other ) {
	
	Rect i = intersect( other );
	if ((i.width() == 0 && i.height() >= 3) || 
		(i.height() == 0 && i.width() >= 3)) {
		neigbours.add( other );
		other.neigbours.add( this );
	}
	
}
 
Example 9
Source File: Room.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void addNeigbour( Room other ) {
	
	Rect i = intersect( other );
	if ((i.width() == 0 && i.height() >= 3) ||
		(i.height() == 0 && i.width() >= 3)) {
		neigbours.add( other );
		other.neigbours.add( this );
	}
	
}
 
Example 10
Source File: Room.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public void addNeighbour(Room other) {
	
	Rect i = intersect( other );
	if ((i.width() == 0 && i.height() >= 3) || 
		(i.height() == 0 && i.width() >= 3)) {
		neighbours.add(other);
		other.neighbours.add(this);
	}
	
}
 
Example 11
Source File: SegmentedRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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);
	
	}
}
 
Example 12
Source File: RegularLevel.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 13
Source File: RegularLevel.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 14
Source File: RegularPainter.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 15
Source File: RegularPainter.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 16
Source File: Builder.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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 17
Source File: RegularLevel.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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;
	}
 
Example 18
Source File: Builder.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: SegmentedRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
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);
	
	}
}
 
Example 20
Source File: RegularLevel.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
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;
}