Java Code Examples for com.watabou.utils.Point

The following examples show how to use com.watabou.utils.Point. These examples are extracted from open source projects. 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
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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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
@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 14
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 15
@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 16
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 17
Source Project: shattered-pixel-dungeon   Source File: Room.java    License: 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 18
public int screenToTile( int x, int y ) {
	Point p = camera().screenToCamera( x, y ).
		offset( this.point().negate() ).
		invScale( SIZE ).
		floor();
	return p.x >= 0 && p.x < Level.WIDTH && p.y >= 0 && p.y < Level.HEIGHT ? p.x + p.y * Level.WIDTH : -1;
}
 
Example 19
@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 20
@Override
public void paint(Level level) {
	Painter.fill(level, this, Terrain.WALL);
	Painter.fill(level, this, 1, Terrain.EMPTY_SP);
	
	Point c = center();
	
	Painter.fill(level, c.x-1, c.y-1, 3, 3, Terrain.WATER);
	Painter.set(level, c, Terrain.GRASS);
	
	if (!Dungeon.isChallenged(Challenges.NO_FOOD)) {
		level.plant(new BlandfruitBush.Seed(), level.pointToCell(c));
	}
	
	int extraFood = (int)(Hunger.STARVING - Hunger.HUNGRY) * (1 + Dungeon.depth / 5);
	
	while (extraFood > 0){
		Food food;
		if (extraFood >= Hunger.STARVING){
			food = new Pasty();
			extraFood -= Hunger.STARVING;
		} else {
			food = new ChargrilledMeat();
			extraFood -= (Hunger.STARVING - Hunger.HUNGRY);
		}
		int foodPos;
		do {
			foodPos = level.pointToCell(random());
		} while (level.map[foodPos] != Terrain.EMPTY_SP || level.heaps.get(foodPos) != null);
		level.drop(food, foodPos);
	}
	
	entrance().set(Door.Type.HIDDEN);
}
 
Example 21
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 22
private static void paintStudy( Level level, Room room ) {

        fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 , Terrain.EMPTY_SP );

        if (room.width() > room.height()) {
            for (int i=room.left + 2; i < room.right; i += 2) {
                fill( level, i, room.top + 2, 1, room.height() - 3, Terrain.BOOKSHELF );
            }
        } else {
            for (int i=room.top + 2; i < room.bottom; i += 2) {
                fill( level, room.left + 2, i, room.width() - 3, 1, Terrain.BOOKSHELF );
            }
        }

//		fill( bonus, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 , Terrain.SHELF_EMPTY );
//		fill( bonus, 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_SP );
			} else if (door.x == room.right) {
				set( level, door.x - 1, door.y, Terrain.EMPTY_SP );
			} else if (door.y == room.top) {
				set( level, door.x, door.y + 1, Terrain.EMPTY_SP );
			} else if (door.y == room.bottom) {
				set( level, door.x , door.y - 1, Terrain.EMPTY_SP );
			}
		}
//
//		set( bonus, room.center(), Terrain.PEDESTAL );
	}
 
Example 23
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 24
@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 25
public static void paint( Level level, Room room ) {
	
	fill( level, room, Terrain.WALL );
	fill( level, room, 1, Terrain.EMPTY_SP );
	
	pasWidth = room.width() - 2;
	pasHeight = room.height() - 2;
	int per = pasWidth * 2 + pasHeight * 2;
	
	if (itemsToSpawn == null)
		generateItems();
	
	int pos = xy2p( room, room.entrance() ) + (per - itemsToSpawn.size()) / 2;
	for (Item item : itemsToSpawn) {
		
		Point xy = p2xy( room, (pos + per) % per );
		int cell = xy.x + xy.y * Level.WIDTH;
		
		if (level.heaps.get( cell ) != null) {
			do {
				cell = room.random();
			} while (level.heaps.get( cell ) != null);
		}
		
		level.drop( item, cell ).type = Heap.Type.FOR_SALE;
		
		pos++;
	}
	
	placeShopkeeper( level, room );
	
	for (Room.Door door : room.connected.values()) {
		door.set( Room.Door.Type.REGULAR );
	}

	itemsToSpawn = null;
}
 
Example 26
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 27
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 28
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 29
Source Project: remixed-dungeon   Source File: ScrollPane.java    License: 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 30
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;
		}

	}