Java Code Examples for com.watabou.utils.PathFinder#setMapSize()
The following examples show how to use
com.watabou.utils.PathFinder#setMapSize() .
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: Level.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 6 votes |
public void setSize(int w, int h){ width = w; height = h; length = w * h; map = new int[length]; Arrays.fill( map, feeling == Level.Feeling.CHASM ? Terrain.CHASM : Terrain.WALL ); visited = new boolean[length]; mapped = new boolean[length]; heroFOV = new boolean[length]; passable = new boolean[length]; losBlocking = new boolean[length]; flamable = new boolean[length]; secret = new boolean[length]; solid = new boolean[length]; avoid = new boolean[length]; water = new boolean[length]; pit = new boolean[length]; PathFinder.setMapSize(w, h); }
Example 2
Source File: Level.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public void setSize(int w, int h){ width = w; height = h; length = w * h; map = new int[length]; Arrays.fill( map, feeling == Level.Feeling.CHASM ? Terrain.CHASM : Terrain.WALL ); visited = new boolean[length]; mapped = new boolean[length]; heroFOV = new boolean[length]; passable = new boolean[length]; losBlocking = new boolean[length]; flamable = new boolean[length]; secret = new boolean[length]; solid = new boolean[length]; avoid = new boolean[length]; water = new boolean[length]; pit = new boolean[length]; openSpace = new boolean[length]; PathFinder.setMapSize(w, h); }
Example 3
Source File: Dungeon.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
public static void initSizeDependentStuff(int w, int h) { int size = w * h; Actor.clear(); visible = new boolean[size]; passable = new boolean[size]; Arrays.fill(visible, false); PathFinder.setMapSize(w, h); }
Example 4
Source File: Dungeon.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 4 votes |
public static void init() { challenges = YetAnotherPixelDungeon.challenges(); Actor.clear(); PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT ); Scroll.initLabels(); Potion.initColors(); Wand.initWoods(); Ring.initGems(); Statistics.reset(); Journal.reset(); depth = 0; gold = 0; droppedItems = new SparseArray<ArrayList<Item>>(); potionOfStrength = 0; potionOfExperience = 0; scrollsOfUpgrade = 0; scrollsOfEnchantment = 0; ankhs = 0; wands = 0; rings = 0; ammos = 0; bottles = 0; scrolls = 0; torches = 0; chapters = new HashSet<Integer>(); Ghost.Quest.reset(); Wandmaker.Quest.reset(); Blacksmith.Quest.reset(); AmbitiousImp.Quest.reset(); Room.shuffleTypes(); ShopPainter.initAssortment(); QuickSlot.quickslotValue_1 = null; QuickSlot.quickslotValue_2 = null; QuickSlot.quickslotValue_3 = null; hero = new Hero(); Buff.affect( hero, Satiety.class ).setValue( Satiety.MAXIMUM ); Buff.affect( hero, Recharging.class ); Badges.reset(); StartScene.curClass.initHero( hero ); }
Example 5
Source File: Dungeon.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
public static void init() { difficultyLevel = ShatteredPixelDungeon.getDifficulty(); version = Game.versionCode; challenges = ShatteredPixelDungeon.challenges(); Generator.initArtifacts(); Actor.clear(); Actor.resetNextID(); PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT ); Scroll.initLabels(); Potion.initColors(); Ring.initGems(); Statistics.reset(); Journal.reset(); quickslot.reset(); QuickSlotButton.reset(); depth = 0; gold = 0; if (difficultyLevel == DIFF_TUTOR) { tutorial_mob_seen = false; tutorial_tactics_tip = false; tutorial_food_found = false; tutorial_sign_seen = false; tutorial_key_found = false; tutorial_altar_seen = false; tutorial_wellA_seen = false; tutorial_wellT_seen = false; tutorial_wellH_seen = false; tutorial_boss_found = false; tutorial_garden_found = false; } droppedItems = new SparseArray<>(); for (limitedDrops a : limitedDrops.values()) a.count = 0; switch (difficultyLevel) { case DIFF_ENDLESS: transmutation = Random.IntRange( 6, 14 ); altarLevel = 5; break; case DIFF_TUTOR: case DIFF_EASY: transmutation = Random.IntRange( 4, 10 ); altarLevel = Random.IntRange(1, 3); break; case DIFF_HARD: transmutation = Random.IntRange( 6, 14 ); altarLevel = Random.IntRange(3, 5); break; case DIFF_NTMARE: transmutation = Random.IntRange( 6, 15 ); altarLevel = Random.IntRange(3, 6); break; case DIFF_TEST: case DIFF_NORM: default: transmutation = Random.IntRange( 6, 14 ); altarLevel = Random.IntRange(2, 4); break; } chapters = new HashSet<>(); Ghost.Quest.reset(); Wandmaker.Quest.reset(); Blacksmith.Quest.reset(); Imp.Quest.reset(); Room.shuffleTypes(); hero = new Hero(); hero.live(); Badges.reset(); StartScene.curClass.initHero( hero ); // remove in progress game files.. // DSM-xxxx this is what is destroying our Rankings scene //for(String fileName : Game.instance.fileList()){ // if(fileName.startsWith("game_") || fileName.endsWith(".dat") && (fileName.startsWith(hero.heroClass.title()))){ // Game.instance.deleteFile(fileName); // } //} }
Example 6
Source File: Dungeon.java From pixel-dungeon with GNU General Public License v3.0 | 4 votes |
public static void loadGame( String fileName, boolean fullLoad ) throws IOException { Bundle bundle = gameBundle( fileName ); Dungeon.challenges = bundle.getInt( CHALLENGES ); Dungeon.level = null; Dungeon.depth = -1; if (fullLoad) { PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT ); } Scroll.restore( bundle ); Potion.restore( bundle ); Wand.restore( bundle ); Ring.restore( bundle ); potionOfStrength = bundle.getInt( POS ); scrollsOfUpgrade = bundle.getInt( SOU ); scrollsOfEnchantment = bundle.getInt( SOE ); dewVial = bundle.getBoolean( DV ); if (fullLoad) { chapters = new HashSet<Integer>(); int ids[] = bundle.getIntArray( CHAPTERS ); if (ids != null) { for (int id : ids) { chapters.add( id ); } } Bundle quests = bundle.getBundle( QUESTS ); if (!quests.isNull()) { Ghost.Quest.restoreFromBundle( quests ); Wandmaker.Quest.restoreFromBundle( quests ); Blacksmith.Quest.restoreFromBundle( quests ); Imp.Quest.restoreFromBundle( quests ); } else { Ghost.Quest.reset(); Wandmaker.Quest.reset(); Blacksmith.Quest.reset(); Imp.Quest.reset(); } Room.restoreRoomsFromBundle( bundle ); } Bundle badges = bundle.getBundle( BADGES ); if (!badges.isNull()) { Badges.loadLocal( badges ); } else { Badges.reset(); } QuickSlot.restore( bundle ); @SuppressWarnings("unused") String version = bundle.getString( VERSION ); hero = null; hero = (Hero)bundle.get( HERO ); QuickSlot.compress(); gold = bundle.getInt( GOLD ); depth = bundle.getInt( DEPTH ); Statistics.restoreFromBundle( bundle ); Journal.restoreFromBundle( bundle ); droppedItems = new SparseArray<ArrayList<Item>>(); for (int i=2; i <= Statistics.deepestFloor + 1; i++) { ArrayList<Item> dropped = new ArrayList<Item>(); for (Bundlable b : bundle.getCollection( String.format( DROPPED, i ) ) ) { dropped.add( (Item)b ); } if (!dropped.isEmpty()) { droppedItems.put( i, dropped ); } } }
Example 7
Source File: Dungeon.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
public static void switchLevel( final Level level, int pos ) { if (pos == -2){ pos = level.exit; } else if (pos < 0 || pos >= level.length()){ pos = level.entrance; } PathFinder.setMapSize(level.width(), level.height()); Dungeon.level = level; Mob.restoreAllies( level, pos ); Actor.init(); Actor respawner = level.respawner(); if (respawner != null) { Actor.addDelayed( respawner, level.respawnTime() ); } hero.pos = pos; for(Mob m : level.mobs){ if (m.pos == hero.pos){ //displace mob for(int i : PathFinder.NEIGHBOURS8){ if (Actor.findChar(m.pos+i) == null && level.passable[m.pos + i]){ m.pos += i; break; } } } } Light light = hero.buff( Light.class ); hero.viewDistance = light == null ? level.viewDistance : Math.max( Light.DISTANCE, level.viewDistance ); hero.curAction = hero.lastAction = null; //pre-0.7.1 saves. Adjusting for spirit bows in weapon slot or with upgrades. SpiritBow bow; if (hero.belongings.weapon instanceof SpiritBow){ bow = (SpiritBow)hero.belongings.weapon; hero.belongings.weapon = null; if (!bow.collect()){ level.drop(bow, hero.pos); } } else { bow = hero.belongings.getItem(SpiritBow.class); } //pre-0.7.1 saves. refunding upgrades previously spend on a boomerang if (bow != null && bow.spentUpgrades() > 0){ ScrollOfUpgrade refund = new ScrollOfUpgrade(); refund.quantity(bow.spentUpgrades()); bow.level(0); //to prevent exploits, some SoU are lost in the conversion of a boomerang higher than +1 if (refund.quantity() > 1){ refund.quantity(1 + (int)Math.floor((refund.quantity()-1)*0.8f)); } if (!refund.collect()){ level.drop(refund, hero.pos); } } observe(); try { saveAll(); } catch (IOException e) { ShatteredPixelDungeon.reportException(e); /*This only catches IO errors. Yes, this means things can go wrong, and they can go wrong catastrophically. But when they do the user will get a nice 'report this issue' dialogue, and I can fix the bug.*/ } }
Example 8
Source File: PatchRoom.java From shattered-pixel-dungeon 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 9
Source File: SecretMazeRoom.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override public void paint(Level level) { Painter.fill(level, this, Terrain.WALL); Painter.fill(level, this, 1, Terrain.EMPTY); //true = space, false = wall Maze.allowDiagonals = false; boolean[][] maze = Maze.generate(this); boolean[] passable = new boolean[width()*height()]; Painter.fill(level, this, 1, Terrain.EMPTY); for (int x = 0; x < maze.length; x++) { for (int y = 0; y < maze[0].length; y++) { if (maze[x][y] == Maze.FILLED) { Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL); } passable[x + width()*y] = maze[x][y] == Maze.EMPTY; } } PathFinder.setMapSize(width(), height()); Point entrance = entrance(); int entrancePos = (entrance.x - left) + width()*(entrance.y - top); PathFinder.buildDistanceMap( entrancePos, passable ); int bestDist = 0; Point bestDistP = new Point(); for (int i = 0; i < PathFinder.distance.length; i++){ if (PathFinder.distance[i] != Integer.MAX_VALUE && PathFinder.distance[i] > bestDist){ bestDist = PathFinder.distance[i]; bestDistP.x = (i % width()) + left; bestDistP.y = (i / width()) + top; } } Item prize; //1 floor set higher in probability, never cursed do { if (Random.Int(2) == 0) { prize = Generator.randomWeapon((Dungeon.depth / 5) + 1); } else { prize = Generator.randomArmor((Dungeon.depth / 5) + 1); } } while (prize.cursed || Challenges.isItemBlocked(prize)); //33% chance for an extra update. if (Random.Int(3) == 0){ prize.upgrade(); } level.drop(prize, level.pointToCell(bestDistP)).type = Heap.Type.CHEST; PathFinder.setMapSize(level.width(), level.height()); entrance().set(Door.Type.HIDDEN); }
Example 10
Source File: Dungeon.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
public static void switchLevel( final Level level, int pos ) { if (pos == -2){ pos = level.exit; } else if (pos < 0 || pos >= level.length()){ pos = level.entrance; } PathFinder.setMapSize(level.width(), level.height()); Dungeon.level = level; Mob.restoreAllies( level, pos ); Actor.init(); Actor respawner = level.respawner(); if (respawner != null) { Actor.addDelayed( respawner, level.respawnTime() ); } hero.pos = pos; for(Mob m : level.mobs){ if (m.pos == hero.pos){ //displace mob for(int i : PathFinder.NEIGHBOURS8){ if (Actor.findChar(m.pos+i) == null && level.passable[m.pos + i]){ m.pos += i; break; } } } } Light light = hero.buff( Light.class ); hero.viewDistance = light == null ? level.viewDistance : Math.max( Light.DISTANCE, level.viewDistance ); hero.curAction = hero.lastAction = null; //pre-0.7.1 saves. Adjusting for spirit bows in weapon slot or with upgrades. SpiritBow bow; if (hero.belongings.weapon instanceof SpiritBow){ bow = (SpiritBow)hero.belongings.weapon; hero.belongings.weapon = null; if (!bow.collect()){ level.drop(bow, hero.pos); } } else { bow = hero.belongings.getItem(SpiritBow.class); } //pre-0.7.1 saves. refunding upgrades previously spend on a boomerang if (bow != null && bow.spentUpgrades() > 0){ ScrollOfUpgrade refund = new ScrollOfUpgrade(); refund.quantity(bow.spentUpgrades()); bow.level(0); //to prevent exploits, some SoU are lost in the conversion of a boomerang higher than +1 if (refund.quantity() > 1){ refund.quantity(1 + (int)Math.floor((refund.quantity()-1)*0.8f)); } if (!refund.collect()){ level.drop(refund, hero.pos); } } observe(); try { saveAll(); } catch (IOException e) { ShatteredPixelDungeon.reportException(e); /*This only catches IO errors. Yes, this means things can go wrong, and they can go wrong catastrophically. But when they do the user will get a nice 'report this issue' dialogue, and I can fix the bug.*/ } }
Example 11
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 12
Source File: SecretMazeRoom.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
@Override public void paint(Level level) { Painter.fill(level, this, Terrain.WALL); Painter.fill(level, this, 1, Terrain.EMPTY); //true = space, false = wall Maze.allowDiagonals = false; boolean[][] maze = Maze.generate(this); boolean[] passable = new boolean[width()*height()]; Painter.fill(level, this, 1, Terrain.EMPTY); for (int x = 0; x < maze.length; x++) { for (int y = 0; y < maze[0].length; y++) { if (maze[x][y] == Maze.FILLED) { Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL); } passable[x + width()*y] = maze[x][y] == Maze.EMPTY; } } PathFinder.setMapSize(width(), height()); Point entrance = entrance(); int entrancePos = (entrance.x - left) + width()*(entrance.y - top); PathFinder.buildDistanceMap( entrancePos, passable ); int bestDist = 0; Point bestDistP = new Point(); for (int i = 0; i < PathFinder.distance.length; i++){ if (PathFinder.distance[i] != Integer.MAX_VALUE && PathFinder.distance[i] > bestDist){ bestDist = PathFinder.distance[i]; bestDistP.x = (i % width()) + left; bestDistP.y = (i / width()) + top; } } Item prize; //1 floor set higher in probability, never cursed do { if (Random.Int(2) == 0) { prize = Generator.randomWeapon((Dungeon.depth / 5) + 1); } else { prize = Generator.randomArmor((Dungeon.depth / 5) + 1); } } while (prize.cursed || Challenges.isItemBlocked(prize)); //33% chance for an extra update. if (Random.Int(3) == 0){ prize.upgrade(); } level.drop(prize, level.pointToCell(bestDistP)).type = Heap.Type.CHEST; PathFinder.setMapSize(level.width(), level.height()); entrance().set(Door.Type.HIDDEN); }
Example 13
Source File: Dungeon.java From pixel-dungeon with GNU General Public License v3.0 | 2 votes |
public static void init() { challenges = PixelDungeon.challenges(); Actor.clear(); PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT ); Scroll.initLabels(); Potion.initColors(); Wand.initWoods(); Ring.initGems(); Statistics.reset(); Journal.reset(); depth = 0; gold = 0; droppedItems = new SparseArray<ArrayList<Item>>(); potionOfStrength = 0; scrollsOfUpgrade = 0; scrollsOfEnchantment = 0; dewVial = true; chapters = new HashSet<Integer>(); Ghost.Quest.reset(); Wandmaker.Quest.reset(); Blacksmith.Quest.reset(); Imp.Quest.reset(); Room.shuffleTypes(); QuickSlot.primaryValue = null; QuickSlot.secondaryValue = null; hero = new Hero(); hero.live(); Badges.reset(); StartScene.curClass.initHero( hero ); }