com.watabou.utils.Point Java Examples

The following examples show how to use com.watabou.utils.Point. 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: RegularPainter.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
protected void paintWater( Level l, ArrayList<Room> rooms ){
	boolean[] lake = Patch.generate( l.width(), l.height(), waterFill, waterSmoothness, true );
	
	if (!rooms.isEmpty()){
		for (Room r : rooms){
			for (Point p : r.waterPlaceablePoints()){
				int i = l.pointToCell(p);
				if (lake[i] && l.map[i] == Terrain.EMPTY){
					l.map[i] = Terrain.WATER;
				}
			}
		}
	} else {
		for (int i = 0; i < l.length(); i ++) {
			if (lake[i] && l.map[i] == Terrain.EMPTY){
				l.map[i] = Terrain.WATER;
			}
		}
	}
	
}
 
Example #3
Source File: SewerPipeRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
private int distanceBetweenPoints(Point a, Point b){
	//on the same side
	if (a.y == b.y || a.x == b.x){
		return Math.max(spaceBetween(a.x, b.x), spaceBetween(a.y, b.y));
	}
	
	//otherwise...
	//subtract 1 at the end to account for overlap
	return
			Math.min(spaceBetween(left, a.x) + spaceBetween(left, b.x),
					spaceBetween(right, a.x) + spaceBetween(right, b.x))
					+
					Math.min(spaceBetween(top, a.y) + spaceBetween(top, b.y),
							spaceBetween(bottom, a.y) + spaceBetween(bottom, b.y))
					-
					1;
}
 
Example #4
Source File: Painter.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static Point drawInside( Level level, Room room, Point from, int n, int value ) {
	
	Point step = new Point();
	if (from.x == room.left) {
		step.set( +1, 0 );
	} else if (from.x == room.right) {
		step.set( -1, 0 );
	} else if (from.y == room.top) {
		step.set( 0, +1 );
	} else if (from.y == room.bottom) {
		step.set( 0, -1 );
	}
	
	Point p = new Point( from ).offset( step );
	for (int i=0; i < n; i++) {
		if (value != -1) {
			set( level, p, value );
		}
		p.offset( step );
	}
	
	return p;
}
 
Example #5
Source File: WeakFloorPainter.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void paint( Level level, Room room ) {
	
	fill( level, room, Terrain.WALL );
	fill( level, room, 1, Terrain.CHASM );
	
	Room.Door door = room.entrance();
	door.set( Room.Door.Type.REGULAR );
	
	if (door.x == room.left) {
		for (int i=room.top + 1; i < room.bottom; i++) {
			drawInside( level, room, new Point( room.left, i ), Random.IntRange( 1, room.width() - 2 ), Terrain.EMPTY_SP );
		}
	} else if (door.x == room.right) {
		for (int i=room.top + 1; i < room.bottom; i++) {
			drawInside( level, room, new Point( room.right, i ), Random.IntRange( 1, room.width() - 2 ), Terrain.EMPTY_SP );
		}
	} else if (door.y == room.top) {
		for (int i=room.left + 1; i < room.right; i++) {
			drawInside( level, room, new Point( i, room.top ), Random.IntRange( 1, room.height() - 2 ), Terrain.EMPTY_SP );
		}
	} else if (door.y == room.bottom) {
		for (int i=room.left + 1; i < room.right; i++) {
			drawInside( level, room, new Point( i, room.bottom ), Random.IntRange( 1, room.height() - 2 ), Terrain.EMPTY_SP );
		}
	}
}
 
Example #6
Source File: SecretLaboratoryRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public void paint( Level level ) {
	
	Painter.fill( level, this, Terrain.WALL );
	Painter.fill( level, this, 1, Terrain.EMPTY_SP );
	
	entrance().set( Door.Type.HIDDEN );
	
	Point pot = center();
	Painter.set( level, pot, Terrain.ALCHEMY );
	
	Blob.seed( pot.x + level.width() * pot.y, 1+Random.NormalIntRange(20, 30), Alchemy.class, level );
	
	int n = Random.IntRange( 2, 3 );
	HashMap<Class<? extends Potion>, Float> chances = new HashMap<>(potionChances);
	for (int i=0; i < n; i++) {
		int pos;
		do {
			pos = level.pointToCell(random());
		} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null);
		
		Class<?extends Potion> potionCls = Random.chances(chances);
		chances.put(potionCls, 0f);
		level.drop( Reflection.newInstance(potionCls), pos );
	}
	
}
 
Example #7
Source File: SecretLaboratoryRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void paint( Level level ) {
	
	Painter.fill( level, this, Terrain.WALL );
	Painter.fill( level, this, 1, Terrain.EMPTY_SP );
	
	entrance().set( Door.Type.HIDDEN );
	
	Point pot = center();
	Painter.set( level, pot, Terrain.ALCHEMY );
	
	Blob.seed( pot.x + level.width() * pot.y, 1+Random.NormalIntRange(20, 30), Alchemy.class, level );
	
	int n = Random.IntRange( 2, 3 );
	HashMap<Class<? extends Potion>, Float> chances = new HashMap<>(potionChances);
	for (int i=0; i < n; i++) {
		int pos;
		do {
			pos = level.pointToCell(random());
		} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null);
		
		Class<?extends Potion> potionCls = Random.chances(chances);
		chances.put(potionCls, 0f);
		level.drop( Reflection.newInstance(potionCls), pos );
	}
	
}
 
Example #8
Source File: Painter.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public static Point drawInside( Level level, Room room, Point from, int n, int value ) {
	
	Point step = new Point();
	if (from.x == room.left) {
		step.set( +1, 0 );
	} else if (from.x == room.right) {
		step.set( -1, 0 );
	} else if (from.y == room.top) {
		step.set( 0, +1 );
	} else if (from.y == room.bottom) {
		step.set( 0, -1 );
	}
	
	Point p = new Point( from ).offset( step );
	for (int i=0; i < n; i++) {
		if (value != -1) {
			set( level, p, value );
		}
		p.offset( step );
	}
	
	return p;
}
 
Example #9
Source File: Painter.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 6 votes vote down vote up
public static Point drawInside( Level level, Room room, Point from, int n, int value ) {
	
	Point step = new Point();
	if (from.x == room.left) {
		step.set( +1, 0 );
	} else if (from.x == room.right) {
		step.set( -1, 0 );
	} else if (from.y == room.top) {
		step.set( 0, +1 );
	} else if (from.y == room.bottom) {
		step.set( 0, -1 );
	}
	
	Point p = new Point( from ).offset( step );
	for (int i=0; i < n; i++) {
		if (value != -1) {
			set( level, p, value );
		}
		p.offset( step );
	}
	
	return p;
}
 
Example #10
Source File: WeakFloorPainter.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void paint( Level level, Room room ) {
	
	fill( level, room, Terrain.WALL );
	fill( level, room, 1, Terrain.CHASM );
	
	Room.Door door = room.entrance(); 
	door.set( Room.Door.Type.REGULAR );
	
	if (door.x == room.left) {
		for (int i=room.top + 1; i < room.bottom; i++) {
			drawInside( level, room, new Point( room.left, i ), Random.IntRange( 1, room.width() - 2 ), Terrain.EMPTY_SP );
		}
	} else if (door.x == room.right) {
		for (int i=room.top + 1; i < room.bottom; i++) {
			drawInside( level, room, new Point( room.right, i ), Random.IntRange( 1, room.width() - 2 ), Terrain.EMPTY_SP );
		}
	} else if (door.y == room.top) {
		for (int i=room.left + 1; i < room.right; i++) {
			drawInside( level, room, new Point( i, room.top ), Random.IntRange( 1, room.height() - 2 ), Terrain.EMPTY_SP );
		}
	} else if (door.y == room.bottom) {
		for (int i=room.left + 1; i < room.right; i++) {
			drawInside( level, room, new Point( i, room.bottom ), Random.IntRange( 1, room.height() - 2 ), Terrain.EMPTY_SP );
		}
	}
}
 
Example #11
Source File: MagicWellPainter.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void paint( Level level, Room room ) {

		fill( level, room, Terrain.WALL );
		fill( level, room, 1, Terrain.EMPTY );
		
		Point c = room.center();
		set( level, c.x, c.y, Terrain.WELL );
		
		@SuppressWarnings("unchecked")
		Class<? extends WellWater> waterClass = 
			(Class<? extends WellWater>)Random.element( WATERS );
		
		WellWater water = (WellWater)level.blobs.get( waterClass );
		if (water == null) {
			try {
				water = waterClass.newInstance();
			} catch (Exception e) {
				water = null;
			}
		}
		water.seed( c.x + Level.WIDTH * c.y, 1 );
		level.blobs.put( waterClass, water );
		
		room.entrance().set( Room.Door.Type.REGULAR );
	}
 
Example #12
Source File: PerimeterRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
private static int distanceBetweenPoints(Room r, Point a, Point b){
	//on the same side
	if (((a.x == r.left || a.x == r.right) && a.y == b.y)
			|| ((a.y == r.top || a.y == r.bottom) && a.x == b.x)){
		return Math.max(spaceBetween(a.x, b.x), spaceBetween(a.y, b.y));
	}
	
	//otherwise...
	//subtract 1 at the end to account for overlap
	return
			Math.min(spaceBetween(r.left, a.x) + spaceBetween(r.left, b.x),
			spaceBetween(r.right, a.x) + spaceBetween(r.right, b.x))
			+
			Math.min(spaceBetween(r.top, a.y) + spaceBetween(r.top, b.y),
			spaceBetween(r.bottom, a.y) + spaceBetween(r.bottom, b.y))
			-
			1;
}
 
Example #13
Source File: StandardPainter.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
private static void paintStudy( Level level, Room room ) {
	fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 , Terrain.BOOKSHELF );
	fill( level, room.left + 2, room.top + 2, room.width() - 3, room.height() - 3 , Terrain.EMPTY_SP );
	
	for (Point door : room.connected.values()) {
		if (door.x == room.left) {
			set( level, door.x + 1, door.y, Terrain.EMPTY );
		} else if (door.x == room.right) {
			set( level, door.x - 1, door.y, Terrain.EMPTY );
		} else if (door.y == room.top) {
			set( level, door.x, door.y + 1, Terrain.EMPTY );
		} else if (door.y == room.bottom) {
			set( level, door.x , door.y - 1, Terrain.EMPTY );
		}	
	}
	
	set( level, room.center(), Terrain.PEDESTAL );
}
 
Example #14
Source File: ScrollPane.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void layout() {

	content.setPos( 0, 0 );
	controller.x = x;
	controller.y = y;
	controller.width = width;
	controller.height = height;

	Point p = camera().cameraToScreen( x, y );
	Camera cs = content.camera;
	cs.x = p.x;
	cs.y = p.y;
	cs.resize( (int)width, (int)height );

	thumb.visible = height < content.height();
	if (thumb.visible) {
		thumb.scale.set( 2, height * height / content.height() );
		thumb.x = right() - thumb.width();
		thumb.y = y;
	}
}
 
Example #15
Source File: Toolbar.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void reset( Item item, int cell, float endX, float endY ) {
	view( item );
	
	active =
	visible =
		true;
	
	PointF tile = DungeonTerrainTilemap.raisedTileCenterToWorld(cell);
	Point screen = Camera.main.cameraToScreen(tile.x, tile.y);
	PointF start = camera().screenToCamera(screen.x, screen.y);
	
	x = this.startX = start.x - ItemSprite.SIZE / 2;
	y = this.startY = start.y - ItemSprite.SIZE / 2;
	
	this.endX = endX - ItemSprite.SIZE / 2;
	this.endY = endY - ItemSprite.SIZE / 2;
	left = DURATION;
	
	scale.set( startScale = Camera.main.zoom / camera().zoom );
	
}
 
Example #16
Source File: NewCavesBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void restoreFromBundle(Bundle bundle) {
	super.restoreFromBundle(bundle);

	for (CustomTilemap c : customTiles){
		if (c instanceof ArenaVisuals){
			customArenaVisuals = (ArenaVisuals) c;
		}
	}

	//pre-0.8.1 saves that may not have had pylons added
	int gatePos = pointToCell(new Point(gate.left, gate.top));
	if (!locked && solid[gatePos]){

		for (int i : pylonPositions) {
			if (findMob(i) == null) {
				Pylon pylon = new Pylon();
				pylon.pos = i;
				mobs.add(pylon);
			}
		}

	}
}
 
Example #17
Source File: SewerPipeRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
private int distanceBetweenPoints(Point a, Point b){
	//on the same side
	if (a.y == b.y || a.x == b.x){
		return Math.max(spaceBetween(a.x, b.x), spaceBetween(a.y, b.y));
	}
	
	//otherwise...
	//subtract 1 at the end to account for overlap
	return
			Math.min(spaceBetween(left, a.x) + spaceBetween(left, b.x),
					spaceBetween(right, a.x) + spaceBetween(right, b.x))
					+
					Math.min(spaceBetween(top, a.y) + spaceBetween(top, b.y),
							spaceBetween(bottom, a.y) + spaceBetween(bottom, b.y))
					-
					1;
}
 
Example #18
Source File: ScrollPane.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void layout() {
	
	content.setPos( 0, 0 );
	controller.x = x;
	controller.y = y;
	controller.width = width;
	controller.height = height;
	
	Point p = camera().cameraToScreen( x, y );
	Camera cs = content.camera;
	cs.x = p.x;
	cs.y = p.y;
	cs.resize( (int)width, (int)height );
}
 
Example #19
Source File: Room.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public final ArrayList<Point> grassPlaceablePoints(){
	ArrayList<Point> points = new ArrayList<>();
	for (int i = left; i <= right; i++) {
		for (int j = top; j <= bottom; j++) {
			Point p = new Point(i, j);
			if (canPlaceGrass(p)) points.add(p);
		}
	}
	return points;
}
 
Example #20
Source File: WellPainter.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void paint( Level level, Room room ) {

		fill( level, room, Terrain.WALL );
		fill( level, room, 1, Terrain.EMPTY );
		
		Point c = room.center();
		set( level, c.x, c.y, Terrain.WELL );

		WellWater water = (WellWater)level.blobs.get( WellWater.class );
		if (water == null) {
			try {
				water = new WellWater();
			} catch (Exception e) {
				water = null;
			}
		}

        int amount = 3 + Dungeon.chapter() + Random.IntRange( 0, 4 );

        // same as in NNYPD, we decrease amount of water in the non-guaranteed well rooms
        if( Dungeon.depth % 6 != 4 ) {
            amount /= 2;
        }

		water.seed( c.x + Level.WIDTH * c.y, amount );
		level.blobs.put( WellWater.class, water );
		
		room.entrance().set( Room.Door.Type.REGULAR );
	}
 
Example #21
Source File: SecretHoardRoom.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);
	
	Class<? extends Trap> trapClass;
	if (Random.Int(2) == 0){
		trapClass = RockfallTrap.class;
	} else if (Dungeon.depth >= 10){
		trapClass = DisintegrationTrap.class;
	} else {
		trapClass = PoisonDartTrap.class;
	}
	
	int goldPos;
	//half of the internal space of the room
	int totalGold = ((width()-2)*(height()-2))/2;
	
	//no matter how much gold it drops, roughly equals 8 gold stacks.
	float goldRatio = 8 / (float)totalGold;
	for (int i = 0; i < totalGold; i++) {
		do {
			goldPos = level.pointToCell(random());
		} while (level.heaps.get(goldPos) != null);
		Item gold = new Gold().random();
		gold.quantity(Math.round(gold.quantity() * goldRatio));
		level.drop(gold, goldPos);
	}
	
	for (Point p : getPoints()){
		if (Random.Int(2) == 0 && level.map[level.pointToCell(p)] == Terrain.EMPTY){
			level.setTrap(Reflection.newInstance(trapClass).reveal(), level.pointToCell(p));
			Painter.set(level, p, Terrain.TRAP);
		}
	}
	
	entrance().set(Door.Type.HIDDEN);
}
 
Example #22
Source File: RegularPainter.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
protected void paintTraps( Level l, ArrayList<Room> rooms ) {
	ArrayList<Integer> validCells = new ArrayList<>();
	
	if (!rooms.isEmpty()){
		for (Room r : rooms){
			for (Point p : r.trapPlaceablePoints()){
				int i = l.pointToCell(p);
				if (l.map[i] == Terrain.EMPTY){
					validCells.add(i);
				}
			}
		}
	} else {
		for (int i = 0; i < l.length(); i ++) {
			if (l.map[i] == Terrain.EMPTY){
				validCells.add(i);
			}
		}
	}
	
	//no more than one trap every 5 valid tiles.
	nTraps = Math.min(nTraps, validCells.size()/5);
	
	for (int i = 0; i < nTraps; i++) {
		
		Integer trapPos = Random.element(validCells);
		validCells.remove(trapPos); //removes the integer object, not at the index
		
		Trap trap = Reflection.newInstance(trapClasses[Random.chances( trapChances )]).hide();
		l.setTrap( trap, trapPos );
		//some traps will not be hidden
		l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
	}
}
 
Example #23
Source File: MagicWellPainter.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@SneakyThrows
public static void paint( Level level, Room room ) {

	fill( level, room, Terrain.WALL );
	fill( level, room, 1, Terrain.EMPTY );
	
	Point c = room.center();
	set( level, c.x, c.y, Terrain.WELL );
	
	@SuppressWarnings("unchecked")
	Class<? extends WellWater> waterClass = 
		Dungeon.depth >= Dungeon.transmutation ?
		WaterOfTransmutation.class :		
		(Class<? extends WellWater>)Random.element( WATERS );
		
	if (waterClass == WaterOfTransmutation.class) {
		Dungeon.transmutation = Integer.MAX_VALUE;
	}
	
	WellWater water = (WellWater)level.blobs.get( waterClass );
	if (water == null) {
		water = waterClass.newInstance();
	}
	water.seed( c.x + level.getWidth() * c.y, 1 );
	level.blobs.put( waterClass, water );
	
	room.entrance().set( Room.Door.Type.REGULAR );
}
 
Example #24
Source File: NewPrisonBossLevel.java    From shattered-pixel-dungeon 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);
	
	for (Point p : startTorches){
		Painter.set(this, p, Terrain.WALL_DECO);
	}
}
 
Example #25
Source File: FlameDoorPainter.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void paint( Level level, Room room ) {

        fill( level, room, Terrain.WALL );
        fill( level, room, 1, Terrain.EMPTY );

        Point c = room.center();
        int cx = c.x;
        int cy = c.y;

        Room.Door entrance = room.entrance();

        entrance.set( Room.Door.Type.ARCHWAY );
        level.addItemToSpawn(new PotionOfFrost());

        EternalFlame eternalFlame = new EternalFlame();
        eternalFlame.seed(entrance.y * Level.WIDTH + entrance.x, 1);
        level.blobs.put(EternalFlame.class, eternalFlame);

        if (entrance.x == room.left) {
            set( level, new Point( room.right-1, room.top+1 ), Terrain.STATUE );
            set( level, new Point( room.right-1, room.bottom-1 ), Terrain.STATUE );
            cx = room.right - 2;
        } else if (entrance.x == room.right) {
            set( level, new Point( room.left+1, room.top+1 ), Terrain.STATUE );
            set( level, new Point( room.left+1, room.bottom-1 ), Terrain.STATUE );
            cx = room.left + 2;
        } else if (entrance.y == room.top) {
            set( level, new Point( room.left+1, room.bottom-1 ), Terrain.STATUE );
            set( level, new Point( room.right-1, room.bottom-1 ), Terrain.STATUE );
            cy = room.bottom - 2;
        } else if (entrance.y == room.bottom) {
            set( level, new Point( room.left+1, room.top+1 ), Terrain.STATUE );
            set( level, new Point( room.right-1, room.top+1 ), Terrain.STATUE );
            cy = room.top + 2;
        }

        level.drop( prize( level ), cx + cy * Level.WIDTH ).type = Heap.Type.CHEST;
    }
 
Example #26
Source File: StandardPainter.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private static void paintStudy( Level level, Room room ) {
	fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 , Terrain.BOOKSHELF );
	fill( level, room.left + 2, room.top + 2, room.width() - 3, room.height() - 3 , Terrain.EMPTY_SP );

	for (Point door : room.connected.values()) {
		if (door.x == room.left) {
			set( level, door.x + 1, door.y, Terrain.EMPTY );
		} else if (door.x == room.right) {
			set( level, door.x - 1, door.y, Terrain.EMPTY );
		} else if (door.y == room.top) {
			set( level, door.x, door.y + 1, Terrain.EMPTY );
		} else if (door.y == room.bottom) {
			set( level, door.x , door.y - 1, Terrain.EMPTY );
		}
	}
	Point center = room.center();
	set( level, center, Terrain.PEDESTAL );
	if (Random.Int(2) != 0){
		Item prize = level.findPrizeItem();
		if (prize != null) {
			level.drop(prize, (room.center().x + center.y * level.WIDTH));
			return;
		}
	}

	level.drop(Generator.random( Random.oneOf(
			Generator.Category.POTION,
			Generator.Category.SCROLL)), (room.center().x + center.y * level.WIDTH));
}
 
Example #27
Source File: ScrollPane.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void layout() {
	
	content.setPos( 0, 0 );
	controller.x = x;
	controller.y = y;
	controller.width = width;
	controller.height = height;
	
	Point p = camera().cameraToScreen( x, y );
	Camera cs = content.camera;
	cs.x = p.x;
	cs.y = p.y;
	cs.resize( (int)width, (int)height );
}
 
Example #28
Source File: ShopRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
protected void placeItems( Level level ){

		if (itemsToSpawn == null)
			itemsToSpawn = generateItems();

		Point itemPlacement = new Point(entrance());
		if (itemPlacement.y == top){
			itemPlacement.y++;
		} else if (itemPlacement.y == bottom) {
			itemPlacement.y--;
		} else if (itemPlacement.x == left){
			itemPlacement.x++;
		} else {
			itemPlacement.x--;
		}

		for (Item item : itemsToSpawn) {

			if (itemPlacement.x == left+1 && itemPlacement.y != top+1){
				itemPlacement.y--;
			} else if (itemPlacement.y == top+1 && itemPlacement.x != right-1){
				itemPlacement.x++;
			} else if (itemPlacement.x == right-1 && itemPlacement.y != bottom-1){
				itemPlacement.y++;
			} else {
				itemPlacement.x--;
			}

			int cell = level.pointToCell(itemPlacement);

			if (level.heaps.get( cell ) != null) {
				do {
					cell = level.pointToCell(random());
				} while (level.heaps.get( cell ) != null || level.findMob( cell ) != null);
			}

			level.drop( item, cell ).type = Heap.Type.FOR_SALE;
		}

	}
 
Example #29
Source File: Level.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public boolean setCellToWater( boolean includeTraps, int cell ){
	Point p = cellToPoint(cell);

	//if a custom tilemap is over that cell, don't put water there
	for (CustomTilemap cust : customTiles){
		Point custPoint = new Point(p);
		custPoint.x -= cust.tileX;
		custPoint.y -= cust.tileY;
		if (custPoint.x >= 0 && custPoint.y >= 0
				&& custPoint.x < cust.tileW && custPoint.y < cust.tileH){
			if (cust.image(custPoint.x, custPoint.y) != null){
				return false;
			}
		}
	}

	int terr = map[cell];
	if (terr == Terrain.EMPTY || terr == Terrain.GRASS ||
			terr == Terrain.EMBERS || terr == Terrain.EMPTY_SP ||
			terr == Terrain.HIGH_GRASS || terr == Terrain.FURROWED_GRASS
			|| terr == Terrain.EMPTY_DECO){
		set(cell, Terrain.WATER);
		GameScene.updateMap(cell);
		return true;
	} else if (includeTraps && (terr == Terrain.SECRET_TRAP ||
			terr == Terrain.TRAP || terr == Terrain.INACTIVE_TRAP)){
		set(cell, Terrain.WATER);
		Dungeon.level.traps.remove(cell);
		GameScene.updateMap(cell);
		return true;
	}

	return false;
}
 
Example #30
Source File: SecretHoneypotRoom.java    From shattered-pixel-dungeon 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 );
	
	Point brokenPotPos = center();
	
	brokenPotPos.x = (brokenPotPos.x + entrance().x) / 2;
	brokenPotPos.y = (brokenPotPos.y + entrance().y) / 2;
	
	Honeypot.ShatteredPot pot = new Honeypot.ShatteredPot();
	level.drop(pot, level.pointToCell(brokenPotPos));
	
	Bee bee = new Bee();
	bee.spawn( Dungeon.depth );
	bee.HP = bee.HT;
	bee.pos = level.pointToCell(brokenPotPos);
	level.mobs.add( bee );
	
	bee.setPotInfo(level.pointToCell(brokenPotPos), null);
	
	placeItem(new Honeypot(), level);
	
	placeItem( new Bomb().random(), level);
	
	entrance().set(Door.Type.HIDDEN);
}