From 3706092e7b82906c351d5a5b1ee1a8d5e495d9a6 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 21 Oct 2014 20:47:40 -0400 Subject: [PATCH] v0.2.2: falling items now appear on the next depth (potions shatter) --- .../shatteredpixeldungeon/Dungeon.java | 23 ++++++++ .../shatteredpixeldungeon/levels/Level.java | 9 +++ .../levels/features/Chasm.java | 3 +- .../scenes/InterlevelScene.java | 57 ++++++++++++++++--- 4 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 4bce146fa..d584ee685 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -24,6 +24,13 @@ import java.util.Arrays; import java.util.Date; import java.util.HashSet; +import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; +import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire; +import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ParalyticGas; +import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas; +import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfLiquidFlame; +import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfParalyticGas; +import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfToxicGas; import com.watabou.noosa.Game; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; @@ -327,6 +334,22 @@ public class Dungeon { if (respawner != null) { Actor.add( level.respawner() ); } + + for (Potion potion : level.fallingPotions){ + + int cell = level.randomRespawnCell(); + while (cell == -1) + cell = level.randomRespawnCell(); + + if (potion instanceof PotionOfLiquidFlame) + GameScene.add(Blob.seed(cell, 2, Fire.class)); + else if (potion instanceof PotionOfToxicGas) + GameScene.add( Blob.seed( cell, 1000, ToxicGas.class ) ); + else if (potion instanceof PotionOfParalyticGas) + GameScene.add( Blob.seed( cell, 1000, ParalyticGas.class ) ); + + } + level.fallingPotions.clear(); hero.pos = pos != -1 ? pos : level.exit; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index 6963eb216..709948810 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.HashSet; import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit; +import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfMight; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfWealth; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfWeaponUpgrade; @@ -147,6 +148,9 @@ public abstract class Level implements Bundlable { public SparseArray plants; protected ArrayList itemsToSpawn = new ArrayList(); + + public ArrayList fallingItems = new ArrayList(); + public ArrayList fallingPotions = new ArrayList(); public int color1 = 0x004400; public int color2 = 0x88CC44; @@ -164,6 +168,7 @@ public abstract class Level implements Bundlable { private static final String PLANTS = "plants"; private static final String MOBS = "mobs"; private static final String BLOBS = "blobs"; + private static final String FALLING = "falling"; public void create() { @@ -307,6 +312,8 @@ public abstract class Level implements Bundlable { Blob blob = (Blob)b; blobs.put( blob.getClass(), blob ); } + + fallingItems = (ArrayList)bundle.getCollection( FALLING ); buildFlagMaps(); cleanWalls(); @@ -324,6 +331,7 @@ public abstract class Level implements Bundlable { bundle.put( PLANTS, plants.values() ); bundle.put( MOBS, mobs ); bundle.put( BLOBS, blobs.values() ); + bundle.put( FALLING, fallingItems); } public int tunnelTile() { @@ -573,6 +581,7 @@ public abstract class Level implements Bundlable { heap.pos = cell; if (map[cell] == Terrain.CHASM || (Dungeon.level != null && pit[cell])) { GameScene.discard( heap ); + fallingItems.add(item); } else { heaps.put( cell, heap ); GameScene.add( heap ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java index 3aaf9ab18..bba605c9d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java @@ -103,8 +103,7 @@ public class Chasm { } public static void mobFall( Mob mob ) { - // Destroy instead of kill to prevent dropping loot - mob.destroy(); + mob.die( null ); ((MobSprite)mob.sprite).fall(); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java index e51002abb..d3478572c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java @@ -18,7 +18,10 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import java.io.FileNotFoundException; +import java.util.ArrayList; +import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; @@ -245,8 +248,18 @@ public class InterlevelScene extends PixelScene { } private void descend() throws Exception { - - Actor.fixTime(); + + Level level; + ArrayList fallingItems = new ArrayList(); + + if (Dungeon.depth > 0) { + level = Dungeon.level; + + fallingItems = level.fallingItems; + level.fallingItems = new ArrayList(); + } + + Actor.fixTime(); if (Dungeon.hero == null) { Dungeon.init(); if (noStory) { @@ -256,29 +269,57 @@ public class InterlevelScene extends PixelScene { } else { Dungeon.saveLevel(); } - - Level level; + if (Dungeon.depth >= Statistics.deepestFloor) { level = Dungeon.newLevel(); } else { Dungeon.depth++; level = Dungeon.loadLevel( Dungeon.hero.heroClass ); } + + for (Item item : fallingItems){ + int cell = level.randomRespawnCell(); + while (cell == -1) + cell = level.randomRespawnCell(); + + if (!(item instanceof Potion)) + level.drop(item, cell); + else + level.fallingPotions.add((Potion)item); + } + Dungeon.switchLevel( level, level.entrance ); + } private void fall() throws Exception { - - Actor.fixTime(); + + Level level = Dungeon.level; + + ArrayList fallingItems = level.fallingItems; + level.fallingItems = new ArrayList(); + + Actor.fixTime(); Dungeon.saveLevel(); - - Level level; + if (Dungeon.depth >= Statistics.deepestFloor) { level = Dungeon.newLevel(); } else { Dungeon.depth++; level = Dungeon.loadLevel( Dungeon.hero.heroClass ); } + + for (Item item : fallingItems){ + int cell = level.randomRespawnCell(); + while (cell == -1) + cell = level.randomRespawnCell(); + + if (!(item instanceof Potion)) + level.drop(item, cell); + else + level.fallingPotions.add((Potion)item); + } + Dungeon.switchLevel( level, fallIntoPit ? level.pitCell() : level.randomRespawnCell() ); }