com.watabou.utils.Rect Java Examples

The following examples show how to use com.watabou.utils.Rect. 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: RegularLevel.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
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);
		}
	}
}
 
Example #2
Source File: InfiniteLevel.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
protected boolean initRooms() {

        rooms = new HashSet<>();
        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;
    }
 
Example #3
Source File: InfiniteLevel.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
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 );
        }
    }
}
 
Example #4
Source File: RegularLevel.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: RegularLevel.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
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 );
		}
	}
}
 
Example #6
Source File: PlatformRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void paint(Level level) {
	
	Painter.fill( level, this, Terrain.WALL );
	
	Painter.fill( level, this, 1, Terrain.CHASM );
	
	ArrayList<Rect> platforms = new ArrayList<>();
	splitPlatforms( new Rect(left+2, top+2, right-2, bottom-2), platforms);
	
	for (Rect platform : platforms){
		Painter.fill( level, platform.left, platform.top, platform.width()+1, platform.height()+1, Terrain.EMPTY_SP);
	}
	
	for (Door door : connected.values()) {
		door.set( Door.Type.REGULAR );
		Painter.drawInside(level, this, door, 2, Terrain.EMPTY_SP);
	}
	
}
 
Example #7
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 #8
Source File: WalkwayRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@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);
		}
	}
}
 
Example #9
Source File: RingBridgeRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void paint(Level level) {
	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);
		}
	}
}
 
Example #10
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 #11
Source File: RegularPainter.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
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 );
			ArrayList<Point> doorSpots = new ArrayList<>();
			for (Point p : i.getPoints()){
				if (r.canConnect(p) && n.canConnect(p))
					doorSpots.add(p);
			}
			if (doorSpots.isEmpty()){
				ShatteredPixelDungeon.reportException(
						new RuntimeException("Could not place a door! " +
								"r=" + r.getClass().getSimpleName() +
								" n=" + n.getClass().getSimpleName()));
				continue;
			}
			door = new Room.Door(Random.element(doorSpots));
			
			r.connected.put( n, door );
			n.connected.put( r, door );
		}
	}
}
 
Example #12
Source File: BridgeRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@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);
		}
	}
}
 
Example #13
Source File: BridgeRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@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);
		}
	}
}
 
Example #14
Source File: RegularLevel.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
protected boolean initRooms() {
	rooms.clear();
	exits.clear();
	//paintedRoom.clear();

	split(new Rect(0, 0, getWidth() - 1, getHeight() - 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].addNeighbor(ra[j]);
		}
	}

	return true;
}
 
Example #15
Source File: RegularLevel.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 6 votes vote down vote up
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.IntRange( i.top + 1, i.bottom - 1 ) );
			} else {
				door = new Room.Door( 
					Random.IntRange( i.left + 1, i.right - 1 ),
					i.top);
			}

			r.connected.put( n, door );
			n.connected.put( r, door );
		}
	}
}
 
Example #16
Source File: FogOfWar.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void updateFog( int cell, int radius ){
	Rect update = new Rect(
			(cell % mapWidth) - radius,
			(cell / mapWidth) - radius,
			(cell % mapWidth) - radius + 1 + 2*radius,
			(cell / mapWidth) - radius + 1 + 2*radius);
	update.left = Math.max(0, update.left);
	update.top = Math.max(0, update.top);
	update.right = Math.min(mapWidth, update.right);
	update.bottom = Math.min(mapHeight, update.bottom);
	if (update.isEmpty()) return;
	updateFog( update );
}
 
Example #17
Source File: FogOfWar.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public FogOfWar( int mapWidth, int mapHeight ) {
	
	super();

	this.mapWidth = mapWidth;
	this.mapHeight = mapHeight;
	mapLength = mapHeight * mapWidth;
	
	pWidth = mapWidth * PIX_PER_TILE;
	pHeight = mapHeight * PIX_PER_TILE;
	
	width2 = 1;
	while (width2 < pWidth) {
		width2 <<= 1;
	}
	
	height2 = 1;
	while (height2 < pHeight) {
		height2 <<= 1;
	}
	
	float size = DungeonTilemap.SIZE / PIX_PER_TILE;
	width = width2 * size;
	height = height2 * size;

	//TODO might be nice to compartmentalize the pixmap access and modification into texture/texturecache
	Pixmap px = new Pixmap(width2, height2, Pixmap.Format.RGBA8888);
	px.setBlending(Pixmap.Blending.None);
	px.setColor(0x000000FF);
	px.fill();
	SmartTexture tx = new SmartTexture(px, Texture.LINEAR, Texture.CLAMP, false);
	TextureCache.add(FogOfWar.class, tx);
	texture( tx );
	
	scale.set( size, size );

	toUpdate = new ArrayList<>();
	toUpdate.add(new Rect(0, 0, mapWidth, mapHeight));
}
 
Example #18
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 #19
Source File: Room.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void addNeighbor(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 #20
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 #21
Source File: SegmentedRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example #22
Source File: Room.java    From shattered-pixel-dungeon-gdx 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 #23
Source File: RingTunnelRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paint(Level level) {
	super.paint(level);

	int floor = level.tunnelTile();

	Rect ring = getConnectionSpace();

	Painter.fill( level, ring.left, ring.top, 3, 3,  floor);
	Painter.fill( level, ring.left+1, ring.top+1, 1, 1,  Terrain.WALL);
}
 
Example #24
Source File: FogOfWar.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void updateFog(Rect update){
	for (Rect r : toUpdate.toArray(new Rect[0])){
		if (!r.intersect(update).isEmpty()){
			toUpdate.remove(r);
			toUpdate.add(r.union(update));
			return;
		}
	}
	toUpdate.add(update);
}
 
Example #25
Source File: NewPrisonBossLevel.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void setCoveringArea(Rect area){
	tileX = area.left;
	tileY = area.top;
	tileH = area.bottom - area.top;
	tileW = area.right - area.left;
	
	this.area = area;
}
 
Example #26
Source File: FogOfWar.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public FogOfWar( int mapWidth, int mapHeight ) {
	
	super();

	this.mapWidth = mapWidth;
	this.mapHeight = mapHeight;
	mapLength = mapHeight * mapWidth;
	
	pWidth = mapWidth * PIX_PER_TILE;
	pHeight = mapHeight * PIX_PER_TILE;
	
	width2 = 1;
	while (width2 < pWidth) {
		width2 <<= 1;
	}
	
	height2 = 1;
	while (height2 < pHeight) {
		height2 <<= 1;
	}
	
	float size = DungeonTilemap.SIZE / PIX_PER_TILE;
	width = width2 * size;
	height = height2 * size;
	
	BufferTexture tx = new BufferTexture(width2, height2);
	TextureCache.add(FogOfWar.class, tx);
	texture( tx );
	
	scale.set(
		DungeonTilemap.SIZE / PIX_PER_TILE,
		DungeonTilemap.SIZE / PIX_PER_TILE);

	toUpdate = new ArrayList<>();
	toUpdate.add(new Rect(0, 0, mapWidth, mapHeight));
}
 
Example #27
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 #28
Source File: RingTunnelRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paint(Level level) {
	super.paint(level);

	int floor = level.tunnelTile();

	Rect ring = getConnectionSpace();

	Painter.fill( level, ring.left, ring.top, 3, 3,  floor);
	Painter.fill( level, ring.left+1, ring.top+1, 1, 1,  Terrain.WALL);
}
 
Example #29
Source File: NewPrisonBossLevel.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
private void setMapStart(){
	entrance = ENTRANCE_POS;
	exit = 0;
	
	Painter.fill(this, 0, 0, 32, 32, Terrain.WALL);
	
	//Start
	Painter.fill(this, entranceRoom, Terrain.WALL);
	Painter.fill(this, entranceRoom, 1, Terrain.EMPTY);
	Painter.set(this, entrance, Terrain.ENTRANCE);
	
	Painter.fill(this, startHallway, Terrain.WALL);
	Painter.fill(this, startHallway, 1, Terrain.EMPTY);
	
	Painter.set(this, startHallway.left+1, startHallway.top, Terrain.DOOR);
	
	for (Rect r : startCells){
		Painter.fill(this, r, Terrain.WALL);
		Painter.fill(this, r, 1, Terrain.EMPTY);
	}
	
	Painter.set(this, startHallway.left, startHallway.top+5, Terrain.DOOR);
	Painter.set(this, startHallway.right-1, startHallway.top+5, Terrain.DOOR);
	Painter.set(this, startHallway.left, startHallway.top+11, Terrain.DOOR);
	Painter.set(this, startHallway.right-1, startHallway.top+11, Terrain.DOOR);
	
	Painter.fill(this, tenguCell, Terrain.WALL);
	Painter.fill(this, tenguCell, 1, Terrain.EMPTY);
	
	Painter.set(this, tenguCell.left+4, tenguCell.top, Terrain.LOCKED_DOOR);
	
	drop(new IronKey(10), randomPrisonCellPos());
	
	for (Point p : startTorches){
		Painter.set(this, p, Terrain.WALL_DECO);
	}
}
 
Example #30
Source File: NewPrisonBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void setCoveringArea(Rect area){
	tileX = area.left;
	tileY = area.top;
	tileH = area.bottom - area.top;
	tileW = area.right - area.left;
	
	this.area = area;
}