v0.6.0: refactored falling landing position logic

Player can no longer fall ontop of enemies, traps, or items.
This commit is contained in:
Evan Debenham 2017-04-18 17:59:06 -04:00 committed by Evan Debenham
parent 564234ae9d
commit 7ab1e18c91
3 changed files with 21 additions and 10 deletions

View File

@ -763,8 +763,14 @@ public abstract class Level implements Bundlable {
GameScene.updateMap( cell ); GameScene.updateMap( cell );
} }
public int pitCell() { public int fallCell( boolean fallIntoPit ) {
return randomRespawnCell(); int result;
do {
result = randomRespawnCell();
} while (traps.get(result) != null
|| findMob(result) != null
|| heaps.get(result) != null);
return result;
} }
public void press( int cell, Char ch ) { public void press( int cell, Char ch ) {

View File

@ -40,7 +40,6 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.WeakFloorRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom;
@ -53,7 +52,6 @@ import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
public abstract class RegularLevel extends Level { public abstract class RegularLevel extends Level {
@ -374,14 +372,21 @@ public abstract class RegularLevel extends Level {
} }
@Override @Override
public int pitCell() { public int fallCell( boolean fallIntoPit ) {
if (fallIntoPit) {
for (Room room : rooms) { for (Room room : rooms) {
if (room instanceof PitRoom || room.legacyType.equals("PIT")) { if (room instanceof PitRoom || room.legacyType.equals("PIT")) {
return pointToCell(room.random()); int result;
do {
result = pointToCell(room.random());
} while (traps.get(result) != null
|| findMob(result) != null
|| heaps.get(result) != null);
}
} }
} }
return super.pitCell(); return super.fallCell( false );
} }
@Override @Override

View File

@ -233,7 +233,7 @@ public class InterlevelScene extends PixelScene {
Dungeon.depth++; Dungeon.depth++;
level = Dungeon.loadLevel( Dungeon.hero.heroClass ); level = Dungeon.loadLevel( Dungeon.hero.heroClass );
} }
Dungeon.switchLevel( level, fallIntoPit ? level.pitCell() : level.randomRespawnCell() ); Dungeon.switchLevel( level, level.fallCell( fallIntoPit ));
} }
private void ascend() throws IOException { private void ascend() throws IOException {