Java Code Examples for com.watabou.utils.PathFinder#distance()
The following examples show how to use
com.watabou.utils.PathFinder#distance() .
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: WandOfLightning.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 6 votes |
private void arc( Char ch ) { int dist = (Dungeon.level.water[ch.pos] && !ch.flying) ? 2 : 1; ArrayList<Char> hitThisArc = new ArrayList<>(); PathFinder.buildDistanceMap( ch.pos, BArray.not( Dungeon.level.solid, null ), dist ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE){ Char n = Actor.findChar( i ); if (n == Dungeon.hero && PathFinder.distance[i] > 1) //the hero is only zapped if they are adjacent continue; else if (n != null && !affected.contains( n )) { hitThisArc.add(n); } } } affected.addAll(hitThisArc); for (Char hit : hitThisArc){ arcs.add(new Lightning.Arc(ch.sprite.center(), hit.sprite.center())); arc(hit); } }
Example 2
Source File: QuickSlotButton.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
public static int autoAim(Char target, Item item){ //first try to directly target if (item.throwPos(Dungeon.hero, target.pos) == target.pos) { return target.pos; } //Otherwise pick nearby tiles to try and 'angle' the shot, auto-aim basically. PathFinder.buildDistanceMap( target.pos, BArray.not( new boolean[Dungeon.level.length()], null ), 2 ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE && item.throwPos(Dungeon.hero, i) == target.pos) return i; } //couldn't find a cell, give up. return -1; }
Example 3
Source File: EtherealChains.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
@Override public void onSelect(Integer target) { if (target != null && (Dungeon.level.visited[target] || Dungeon.level.mapped[target])){ //chains cannot be used to go where it is impossible to walk to PathFinder.buildDistanceMap(target, BArray.or(Dungeon.level.passable, Dungeon.level.avoid, null)); if (PathFinder.distance[curUser.pos] == Integer.MAX_VALUE){ GLog.w( Messages.get(EtherealChains.class, "cant_reach") ); return; } final Ballistica chain = new Ballistica(curUser.pos, target, Ballistica.STOP_TARGET); if (Actor.findChar( chain.collisionPos ) != null){ chainEnemy( chain, curUser, Actor.findChar( chain.collisionPos )); } else { chainLocation( chain, curUser ); } throwSound(); Sample.INSTANCE.play( Assets.Sounds.CHAINS ); } }
Example 4
Source File: Shocking.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
public static void arc( Char attacker, Char defender, int dist, ArrayList<Char> affected, ArrayList<Lightning.Arc> arcs ) { affected.add(defender); defender.sprite.centerEmitter().burst(SparkParticle.FACTORY, 3); defender.sprite.flash(); PathFinder.buildDistanceMap( defender.pos, BArray.not( Dungeon.level.solid, null ), dist ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { Char n = Actor.findChar(i); if (n != null && n != attacker && !affected.contains(n)) { arcs.add(new Lightning.Arc(defender.sprite.center(), n.sprite.center())); arc(attacker, n, (Dungeon.level.water[n.pos] && !n.flying) ? 2 : 1, affected, arcs); } } } }
Example 5
Source File: CausticBrew.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
@Override public void shatter(int cell) { if (Dungeon.level.heroFOV[cell]) { splash( cell ); Sample.INSTANCE.play( Assets.Sounds.SHATTER ); } PathFinder.buildDistanceMap( cell, BArray.not( Dungeon.level.solid, null ), 3 ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { Splash.at( i, 0x000000, 5); Char ch = Actor.findChar(i); if (ch != null){ Buff.affect(ch, Ooze.class).set( Ooze.DURATION ); } } } }
Example 6
Source File: RogueArmor.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void onSelect( Integer target ) { if (target != null) { PathFinder.buildDistanceMap(curUser.pos, BArray.not(Dungeon.level.solid,null), 8); if ( PathFinder.distance[target] == Integer.MAX_VALUE || !Dungeon.level.heroFOV[target] || Actor.findChar( target ) != null) { GLog.w( Messages.get(RogueArmor.class, "fov") ); return; } charge -= 35; updateQuickslot(); for (Mob mob : Dungeon.level.mobs.toArray(new Mob[0])) { if (Dungeon.level.adjacent(mob.pos, curUser.pos) && mob.alignment != Char.Alignment.ALLY) { Buff.prolong( mob, Blindness.class, Blindness.DURATION/2f ); if (mob.state == mob.HUNTING) mob.state = mob.WANDERING; mob.sprite.emitter().burst( Speck.factory( Speck.LIGHT ), 4 ); } } Buff.affect(curUser, Invisibility.class, Invisibility.DURATION/2f); CellEmitter.get( curUser.pos ).burst( Speck.factory( Speck.WOOL ), 10 ); ScrollOfTeleportation.appear( curUser, target ); Sample.INSTANCE.play( Assets.Sounds.PUFF ); Dungeon.level.occupyCell(curUser ); Dungeon.observe(); GameScene.updateFog(); curUser.spendAndNext( Actor.TICK ); } }
Example 7
Source File: BlazingTrap.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
@Override public void activate() { PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.solid, null ), 2 ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { if (Dungeon.level.pit[i] || Dungeon.level.water[i]) GameScene.add(Blob.seed(i, 1, Fire.class)); else GameScene.add(Blob.seed(i, 5, Fire.class)); CellEmitter.get(i).burst(FlameParticle.FACTORY, 5); } } Sample.INSTANCE.play(Assets.SND_BURNING); }
Example 8
Source File: KindOfWeapon.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
public boolean canReach( Char owner, int target){ if (Dungeon.level.distance( owner.pos, target ) > reachFactor(owner)){ return false; } else { boolean[] passable = BArray.not(Dungeon.level.solid, null); for (Char ch : Actor.chars()) { if (ch != owner) passable[ch.pos] = false; } PathFinder.buildDistanceMap(target, passable, reachFactor(owner)); return PathFinder.distance[owner.pos] <= reachFactor(owner); } }
Example 9
Source File: Piranha.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
@Override public boolean act(boolean enemyInFOV, boolean justAlerted) { if (enemyInFOV) { PathFinder.buildDistanceMap(enemy.pos, Dungeon.level.water, viewDistance); enemyInFOV = PathFinder.distance[pos] != Integer.MAX_VALUE; } return super.act(enemyInFOV, justAlerted); }
Example 10
Source File: FrostBomb.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void explode(int cell) { super.explode(cell); PathFinder.buildDistanceMap( cell, BArray.not( Dungeon.level.solid, null ), 2 ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { GameScene.add(Blob.seed(i, 10, Freezing.class)); Char ch = Actor.findChar(i); if (ch != null){ Buff.affect(ch, Frost.class, 2f); } } } }
Example 11
Source File: FrostTrap.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
@Override public void activate() { if (Dungeon.level.heroFOV[ pos ]){ Splash.at( pos, 0xFFB2D6FF, 5); Sample.INSTANCE.play( Assets.SND_SHATTER ); } PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.solid, null ), 2 ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { GameScene.add(Blob.seed(i, 20, Freezing.class)); } } }
Example 12
Source File: Armor.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public float speedFactor( Char owner, float speed ){ if (owner instanceof Hero) { int aEnc = STRReq() - ((Hero) owner).STR(); if (aEnc > 0) speed /= Math.pow(1.2, aEnc); } if (hasGlyph(Swiftness.class, owner)) { boolean enemyNear = false; PathFinder.buildDistanceMap(owner.pos, Dungeon.level.passable, 2); for (Char ch : Actor.chars()){ if ( PathFinder.distance[ch.pos] != Integer.MAX_VALUE && owner.alignment != ch.alignment){ enemyNear = true; break; } } if (!enemyNear) speed *= (1.2f + 0.04f * buffedLvl()); } else if (hasGlyph(Flow.class, owner) && Dungeon.level.water[owner.pos]){ speed *= (2f + 0.25f*buffedLvl()); } if (hasGlyph(Bulk.class, owner) && (Dungeon.level.map[owner.pos] == Terrain.DOOR || Dungeon.level.map[owner.pos] == Terrain.OPEN_DOOR )) { speed /= 3f; } return speed; }
Example 13
Source File: ScrollOfTeleportation.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public static void teleportToLocation(Hero hero, int pos){ PathFinder.buildDistanceMap(pos, BArray.or(Dungeon.level.passable, Dungeon.level.avoid, null)); if (PathFinder.distance[hero.pos] == Integer.MAX_VALUE || (!Dungeon.level.passable[pos] && !Dungeon.level.avoid[pos]) || Actor.findChar(pos) != null){ GLog.w( Messages.get(ScrollOfTeleportation.class, "cant_reach") ); return; } appear( hero, pos ); Dungeon.level.occupyCell(hero ); Dungeon.observe(); GameScene.updateFog(); }
Example 14
Source File: Icecap.java From pixel-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void activate( Char ch ) { super.activate( ch ); PathFinder.buildDistanceMap( pos, BArray.not( Level.losBlocking, null ), 1 ); Fire fire = (Fire)Dungeon.level.blobs.get( Fire.class ); for (int i=0; i < Level.LENGTH; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { Freezing.affect( i, fire ); } } }
Example 15
Source File: StormTrap.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
@Override public void activate() { if (Dungeon.level.heroFOV[pos]){ Sample.INSTANCE.play( Assets.SND_LIGHTNING ); } PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.solid, null ), 2 ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { GameScene.add(Blob.seed(i, 20, Electricity.class)); } } }
Example 16
Source File: Icecap.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void activate() { PathFinder.buildDistanceMap( pos, BArray.not( Level.losBlocking, null ), 1 ); Fire fire = (Fire)Dungeon.level.blobs.get( Fire.class ); for (int i=0; i < Level.LENGTH; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { Freezing.affect( i, fire ); } } }
Example 17
Source File: Icecap.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void effect(int pos, Presser ch ) { PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.losBlocking, null ), 1 ); for (int i=0; i < Dungeon.level.getLength(); i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { Freezing.affect( i ); } } }
Example 18
Source File: PatchRoom.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
protected void setupPatch(Level level, float fill, int clustering, boolean ensurePath){ if (ensurePath){ PathFinder.setMapSize(width()-2, height()-2); boolean valid; do { patch = Patch.generate(width()-2, height()-2, fill, clustering, true); int startPoint = 0; for (Door door : connected.values()) { if (door.x == left) { startPoint = xyToPatchCoords(door.x + 1, door.y); patch[xyToPatchCoords(door.x + 1, door.y)] = false; patch[xyToPatchCoords(door.x + 2, door.y)] = false; } else if (door.x == right) { startPoint = xyToPatchCoords(door.x - 1, door.y); patch[xyToPatchCoords(door.x - 1, door.y)] = false; patch[xyToPatchCoords(door.x - 2, door.y)] = false; } else if (door.y == top) { startPoint = xyToPatchCoords(door.x, door.y + 1); patch[xyToPatchCoords(door.x, door.y + 1)] = false; patch[xyToPatchCoords(door.x, door.y + 2)] = false; } else if (door.y == bottom) { startPoint = xyToPatchCoords(door.x, door.y - 1); patch[xyToPatchCoords(door.x, door.y - 1)] = false; patch[xyToPatchCoords(door.x, door.y - 2)] = false; } } PathFinder.buildDistanceMap(startPoint, BArray.not(patch, null)); valid = true; for (int i = 0; i < patch.length; i++){ if (!patch[i] && PathFinder.distance[i] == Integer.MAX_VALUE){ valid = false; break; } } } while (!valid); PathFinder.setMapSize(level.width(), level.height()); } else { patch = Patch.generate(width()-2, height()-2, fill, clustering, true); } }
Example 19
Source File: Goo.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override protected boolean doAttack( Char enemy ) { if (pumpedUp == 1) { ((GooSprite)sprite).pumpUp(); PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.solid, null ), 2 ); for (int i = 0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) GameScene.add(Blob.seed(i, 1, GooWarn.class)); } pumpedUp++; Sample.INSTANCE.play( Assets.Sounds.CHARGEUP ); spend( attackDelay() ); return true; } else if (pumpedUp >= 2 || Random.Int( (HP*2 <= HT) ? 2 : 5 ) > 0) { boolean visible = Dungeon.level.heroFOV[pos]; if (visible) { if (pumpedUp >= 2) { ((GooSprite) sprite).pumpAttack(); } else sprite.attack( enemy.pos ); } else { attack( enemy ); } spend( attackDelay() ); return !visible; } else { pumpedUp++; ((GooSprite)sprite).pumpUp(); for (int i=0; i < PathFinder.NEIGHBOURS9.length; i++) { int j = pos + PathFinder.NEIGHBOURS9[i]; if (!Dungeon.level.solid[j]) { GameScene.add(Blob.seed(j, 1, GooWarn.class)); } } if (Dungeon.level.heroFOV[pos]) { sprite.showStatus( CharSprite.NEGATIVE, Messages.get(this, "!!!") ); GLog.n( Messages.get(this, "pumpup") ); Sample.INSTANCE.play( Assets.Sounds.CHARGEUP, 1f, 0.8f ); } spend( attackDelay() ); return true; } }
Example 20
Source File: PotionOfPurity.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override public void shatter( int cell ) { PathFinder.buildDistanceMap( cell, BArray.not( Dungeon.level.solid, null ), DISTANCE ); ArrayList<Blob> blobs = new ArrayList<>(); for (Class c : affectedBlobs){ Blob b = Dungeon.level.blobs.get(c); if (b != null && b.volume > 0){ blobs.add(b); } } for (int i=0; i < Dungeon.level.length(); i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { for (Blob blob : blobs) { int value = blob.cur[i]; if (value > 0) { blob.clear(i); blob.cur[i] = 0; blob.volume -= value; } } if (Dungeon.level.heroFOV[i]) { CellEmitter.get( i ).burst( Speck.factory( Speck.DISCOVER ), 2 ); } } } if (Dungeon.level.heroFOV[cell]) { splash(cell); Sample.INSTANCE.play(Assets.Sounds.SHATTER); setKnown(); GLog.i(Messages.get(this, "freshness")); } }