Java Code Examples for com.watabou.utils.PathFinder#CIRCLE8

The following examples show how to use com.watabou.utils.PathFinder#CIRCLE8 . 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: NewTengu.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static boolean throwFire(final Char thrower, final Char target){
	
	Ballistica aim = new Ballistica(thrower.pos, target.pos, Ballistica.WONT_STOP);
	
	for (int i = 0; i < PathFinder.CIRCLE8.length; i++){
		if (aim.sourcePos+PathFinder.CIRCLE8[i] == aim.path.get(1)){
			thrower.sprite.zap(target.pos);
			Buff.append(thrower, NewTengu.FireAbility.class).direction = i;
			
			thrower.sprite.emitter().start(Speck.factory(Speck.STEAM), .03f, 10);
			return true;
		}
	}
	
	return false;
}
 
Example 2
Source File: Spinner.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void shootWeb(){
	int webPos = webPos();
	if (enemy != null && webPos != enemy.pos && webPos != -1){
		int i;
		for ( i = 0; i < PathFinder.CIRCLE8.length; i++){
			if ((enemy.pos + PathFinder.CIRCLE8[i]) == webPos){
				break;
			}
		}
		
		//spread to the tile hero was moving towards and the two adjacent ones
		int leftPos = enemy.pos + PathFinder.CIRCLE8[left(i)];
		int rightPos = enemy.pos + PathFinder.CIRCLE8[right(i)];
		
		if (Dungeon.level.passable[leftPos]) GameScene.add(Blob.seed(leftPos, 20, Web.class));
		if (Dungeon.level.passable[webPos])  GameScene.add(Blob.seed(webPos, 20, Web.class));
		if (Dungeon.level.passable[rightPos])GameScene.add(Blob.seed(rightPos, 20, Web.class));
		
		webCoolDown = 10;

		if (Dungeon.level.heroFOV[enemy.pos]){
			Dungeon.hero.interrupt();
		}
	}
	next();
}
 
Example 3
Source File: NewTengu.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public static boolean throwFire(final Char thrower, final Char target){
	
	Ballistica aim = new Ballistica(thrower.pos, target.pos, Ballistica.WONT_STOP);
	
	for (int i = 0; i < PathFinder.CIRCLE8.length; i++){
		if (aim.sourcePos+PathFinder.CIRCLE8[i] == aim.path.get(1)){
			thrower.sprite.zap(target.pos);
			Buff.append(thrower, NewTengu.FireAbility.class).direction = i;
			
			thrower.sprite.emitter().start(Speck.factory(Speck.STEAM), .03f, 10);
			return true;
		}
	}
	
	return false;
}
 
Example 4
Source File: NewTengu.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private void spreadFromCell( int cell ){
	if (!Dungeon.level.solid[cell + PathFinder.CIRCLE8[left(direction)]]){
		toCells.add(cell + PathFinder.CIRCLE8[left(direction)]);
	}
	if (!Dungeon.level.solid[cell + PathFinder.CIRCLE8[direction]]){
		toCells.add(cell + PathFinder.CIRCLE8[direction]);
	}
	if (!Dungeon.level.solid[cell + PathFinder.CIRCLE8[right(direction)]]){
		toCells.add(cell + PathFinder.CIRCLE8[right(direction)]);
	}
}
 
Example 5
Source File: NewTengu.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private void spreadblob(){
	GameScene.add(Blob.seed(shockerPos, 1, ShockerBlob.class));
	for (int i = shockingOrdinals ? 0 : 1; i < PathFinder.CIRCLE8.length; i += 2){
		if (!Dungeon.level.solid[shockerPos+PathFinder.CIRCLE8[i]]) {
			GameScene.add(Blob.seed(shockerPos + PathFinder.CIRCLE8[i], 2, ShockerBlob.class));
		}
	}
}
 
Example 6
Source File: Pylon.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean act() {
	spend(TICK);

	Heap heap = Dungeon.level.heaps.get( pos );
	if (heap != null) {
		int n;
		do {
			n = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )];
		} while (!Dungeon.level.passable[n] && !Dungeon.level.avoid[n]);
		Dungeon.level.drop( heap.pickUp(), n ).sprite.drop( pos );
	}

	if (alignment == Alignment.NEUTRAL){
		return true;
	}

	int cell1 = pos + PathFinder.CIRCLE8[targetNeighbor];
	int cell2 = pos + PathFinder.CIRCLE8[(targetNeighbor+4)%8];

	sprite.flash();
	if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[cell1] || Dungeon.level.heroFOV[cell2]) {
		sprite.parent.add(new Lightning(DungeonTilemap.raisedTileCenterToWorld(cell1),
				DungeonTilemap.raisedTileCenterToWorld(cell2), null));
		CellEmitter.get(cell1).burst(SparkParticle.FACTORY, 3);
		CellEmitter.get(cell2).burst(SparkParticle.FACTORY, 3);
		Sample.INSTANCE.play( Assets.Sounds.LIGHTNING );
	}

	shockChar(Actor.findChar(cell1));
	shockChar(Actor.findChar(cell2));

	targetNeighbor = (targetNeighbor+1)%8;

	return true;
}
 
Example 7
Source File: Level.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void set( int cell, int terrain, Level level ) {
	Painter.set( level, cell, terrain );

	if (terrain != Terrain.TRAP && terrain != Terrain.SECRET_TRAP && terrain != Terrain.INACTIVE_TRAP){
		level.traps.remove( cell );
	}

	int flags = Terrain.flags[terrain];
	level.passable[cell]		= (flags & Terrain.PASSABLE) != 0;
	level.losBlocking[cell]	    = (flags & Terrain.LOS_BLOCKING) != 0;
	level.flamable[cell]		= (flags & Terrain.FLAMABLE) != 0;
	level.secret[cell]		    = (flags & Terrain.SECRET) != 0;
	level.solid[cell]			= (flags & Terrain.SOLID) != 0;
	level.avoid[cell]			= (flags & Terrain.AVOID) != 0;
	level.pit[cell]			    = (flags & Terrain.PIT) != 0;
	level.water[cell]			= terrain == Terrain.WATER;

	SmokeScreen s = (SmokeScreen)level.blobs.get(SmokeScreen.class);
	if (s != null && s.volume > 0){
		level.losBlocking[cell] = level.losBlocking[cell] || s.cur[cell] > 0;
	}

	for (int i : PathFinder.NEIGHBOURS9){
		i = cell + i;
		if (level.solid[i]){
			level.openSpace[i] = false;
		} else {
			for (int j = 1; j < PathFinder.CIRCLE8.length; j += 2){
				if (level.solid[i+PathFinder.CIRCLE8[j]]) {
					level.openSpace[i] = false;
				} else if (!level.solid[i+PathFinder.CIRCLE8[(j+1)%8]]
						&& !level.solid[i+PathFinder.CIRCLE8[(j+2)%8]]){
					level.openSpace[i] = true;
					break;
				}
			}
		}
	}
}
 
Example 8
Source File: NewTengu.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
private void spreadFromCell( int cell ){
	if (!Dungeon.level.solid[cell + PathFinder.CIRCLE8[left(direction)]]){
		toCells.add(cell + PathFinder.CIRCLE8[left(direction)]);
	}
	if (!Dungeon.level.solid[cell + PathFinder.CIRCLE8[direction]]){
		toCells.add(cell + PathFinder.CIRCLE8[direction]);
	}
	if (!Dungeon.level.solid[cell + PathFinder.CIRCLE8[right(direction)]]){
		toCells.add(cell + PathFinder.CIRCLE8[right(direction)]);
	}
}
 
Example 9
Source File: NewTengu.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
private void spreadblob(){
	GameScene.add(Blob.seed(shockerPos, 1, ShockerBlob.class));
	for (int i = shockingOrdinals ? 0 : 1; i < PathFinder.CIRCLE8.length; i += 2){
		if (!Dungeon.level.solid[shockerPos+PathFinder.CIRCLE8[i]]) {
			GameScene.add(Blob.seed(shockerPos + PathFinder.CIRCLE8[i], 2, ShockerBlob.class));
		}
	}
}
 
Example 10
Source File: WandOfWarding.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public static boolean canPlaceWard(int pos){

		for (int i : PathFinder.CIRCLE8){
			if (Actor.findChar(pos+i) instanceof Ward){
				return false;
			}
		}

		return true;

	}
 
Example 11
Source File: Level.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public void buildFlagMaps() {
	
	for (int i=0; i < length(); i++) {
		int flags = Terrain.flags[map[i]];
		passable[i]		= (flags & Terrain.PASSABLE) != 0;
		losBlocking[i]	= (flags & Terrain.LOS_BLOCKING) != 0;
		flamable[i]		= (flags & Terrain.FLAMABLE) != 0;
		secret[i]		= (flags & Terrain.SECRET) != 0;
		solid[i]		= (flags & Terrain.SOLID) != 0;
		avoid[i]		= (flags & Terrain.AVOID) != 0;
		water[i]		= (flags & Terrain.LIQUID) != 0;
		pit[i]			= (flags & Terrain.PIT) != 0;
	}
	
	SmokeScreen s = (SmokeScreen)blobs.get(SmokeScreen.class);
	if (s != null && s.volume > 0){
		for (int i=0; i < length(); i++) {
			losBlocking[i] = losBlocking[i] || s.cur[i] > 0;
		}
	}

	Web w = (Web) blobs.get(Web.class);
	if (w != null && w.volume > 0){
		for (int i=0; i < length(); i++) {
			solid[i] = solid[i] || w.cur[i] > 0;
		}
	}
	
	int lastRow = length() - width();
	for (int i=0; i < width(); i++) {
		passable[i] = avoid[i] = false;
		losBlocking[i] = solid[i] = true;
		passable[lastRow + i] = avoid[lastRow + i] = false;
		losBlocking[lastRow + i] = solid[lastRow + i] = true;
	}
	for (int i=width(); i < lastRow; i += width()) {
		passable[i] = avoid[i] = false;
		losBlocking[i] = solid[i] = true;
		passable[i + width()-1] = avoid[i + width()-1] = false;
		losBlocking[i + width()-1] = solid[i + width()-1] = true;
	}

	//an open space is large enough to fit large mobs. A space is open when it is not solid
	// and there is and open corner with both adjacent cells opens
	for (int i=0; i < length(); i++) {
		if (solid[i]){
			openSpace[i] = false;
		} else {
			for (int j = 1; j < PathFinder.CIRCLE8.length; j += 2){
				if (solid[i+PathFinder.CIRCLE8[j]]) {
					openSpace[i] = false;
				} else if (!solid[i+PathFinder.CIRCLE8[(j+1)%8]]
						&& !solid[i+PathFinder.CIRCLE8[(j+2)%8]]){
					openSpace[i] = true;
					break;
				}
			}
		}
	}

}
 
Example 12
Source File: WandOfFireblast.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void fx( Ballistica bolt, Callback callback ) {
	//need to perform flame spread logic here so we can determine what cells to put flames in.
	affectedCells = new HashSet<>();
	visualCells = new HashSet<>();

	// 4/6/8 distance
	int maxDist = 2 + 2*chargesPerCast();
	int dist = Math.min(bolt.dist, maxDist);

	for (int i = 0; i < PathFinder.CIRCLE8.length; i++){
		if (bolt.sourcePos+PathFinder.CIRCLE8[i] == bolt.path.get(1)){
			direction = i;
			break;
		}
	}

	float strength = maxDist;
	for (int c : bolt.subPath(1, dist)) {
		strength--; //as we start at dist 1, not 0.
		affectedCells.add(c);
		if (strength > 1) {
			spreadFlames(c + PathFinder.CIRCLE8[left(direction)], strength - 1);
			spreadFlames(c + PathFinder.CIRCLE8[direction], strength - 1);
			spreadFlames(c + PathFinder.CIRCLE8[right(direction)], strength - 1);
		} else {
			visualCells.add(c);
		}
	}

	//going to call this one manually
	visualCells.remove(bolt.path.get(dist));

	for (int cell : visualCells){
		//this way we only get the cells at the tip, much better performance.
		((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset(
				MagicMissile.FIRE_CONE,
				curUser.sprite,
				cell,
				null
		);
	}
	MagicMissile.boltFromChar( curUser.sprite.parent,
			MagicMissile.FIRE_CONE,
			curUser.sprite,
			bolt.path.get(dist/2),
			callback );
	Sample.INSTANCE.play( Assets.SND_ZAP );
}
 
Example 13
Source File: WandOfRegrowth.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
protected void fx( Ballistica bolt, Callback callback ) {

		affectedCells = new HashSet<>();
		visualCells = new HashSet<>();

		int maxDist = Math.round(1.2f + chargesPerCast()*.8f);
		int dist = Math.min(bolt.dist, maxDist);

		for (int i = 0; i < PathFinder.CIRCLE8.length; i++){
			if (bolt.sourcePos+PathFinder.CIRCLE8[i] == bolt.path.get(1)){
				direction = i;
				break;
			}
		}

		float strength = maxDist;
		for (int c : bolt.subPath(1, dist)) {
			strength--; //as we start at dist 1, not 0.
			if (Dungeon.level.passable[c]) {
				affectedCells.add(c);
				spreadRegrowth(c + PathFinder.CIRCLE8[left(direction)], strength - 1);
				spreadRegrowth(c + PathFinder.CIRCLE8[direction], strength - 1);
				spreadRegrowth(c + PathFinder.CIRCLE8[right(direction)], strength - 1);
			} else {
				visualCells.add(c);
			}
		}

		//going to call this one manually
		visualCells.remove(bolt.path.get(dist));

		for (int cell : visualCells){
			//this way we only get the cells at the tip, much better performance.
			((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset(
					MagicMissile.FOLIAGE_CONE,
					curUser.sprite,
					cell,
					null
			);
		}
		MagicMissile.boltFromChar( curUser.sprite.parent,
				MagicMissile.FOLIAGE_CONE,
				curUser.sprite,
				bolt.path.get(dist/2),
				callback );

		Sample.INSTANCE.play( Assets.SND_ZAP );
	}