2014-07-27 13:39:07 +00:00
|
|
|
/*
|
|
|
|
* Pixel Dungeon
|
|
|
|
* Copyright (C) 2012-2014 Oleg Dolya
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
2014-08-03 18:46:22 +00:00
|
|
|
package com.shatteredpixel.shatteredpixeldungeon.scenes;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2014-11-16 01:58:42 +00:00
|
|
|
import android.os.Build;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
2014-11-05 14:42:41 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
2014-11-16 01:58:42 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndError;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
|
2014-11-05 14:42:41 +00:00
|
|
|
import com.watabou.noosa.BitmapText;
|
|
|
|
import com.watabou.noosa.Camera;
|
|
|
|
import com.watabou.noosa.Game;
|
|
|
|
import com.watabou.noosa.audio.Music;
|
|
|
|
import com.watabou.noosa.audio.Sample;
|
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
2014-11-16 01:52:02 +00:00
|
|
|
import java.io.IOException;
|
2014-11-05 14:42:41 +00:00
|
|
|
import java.util.ArrayList;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
public class InterlevelScene extends PixelScene {
|
|
|
|
|
|
|
|
private static final float TIME_TO_FADE = 0.3f;
|
|
|
|
|
|
|
|
private static final String TXT_DESCENDING = "Descending...";
|
|
|
|
private static final String TXT_ASCENDING = "Ascending...";
|
|
|
|
private static final String TXT_LOADING = "Loading...";
|
|
|
|
private static final String TXT_RESURRECTING= "Resurrecting...";
|
|
|
|
private static final String TXT_RETURNING = "Returning...";
|
|
|
|
private static final String TXT_FALLING = "Falling...";
|
|
|
|
|
2014-11-25 06:15:11 +00:00
|
|
|
private static final String ERR_FILE_NOT_FOUND = "Save file not found. If this error persists after restarting, " +
|
|
|
|
"it may mean this save game is corrupted. Sorry about that.";
|
|
|
|
private static final String ERR_IO = "Cannot read save file. If this error persists after restarting, " +
|
|
|
|
"it may mean this save game is corrupted. Sorry about that.";
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
public static enum Mode {
|
|
|
|
DESCEND, ASCEND, CONTINUE, RESURRECT, RETURN, FALL
|
|
|
|
};
|
|
|
|
public static Mode mode;
|
|
|
|
|
|
|
|
public static int returnDepth;
|
|
|
|
public static int returnPos;
|
|
|
|
|
|
|
|
public static boolean noStory = false;
|
|
|
|
|
|
|
|
public static boolean fallIntoPit;
|
|
|
|
|
|
|
|
private enum Phase {
|
|
|
|
FADE_IN, STATIC, FADE_OUT
|
|
|
|
};
|
|
|
|
private Phase phase;
|
|
|
|
private float timeLeft;
|
|
|
|
|
|
|
|
private BitmapText message;
|
|
|
|
|
|
|
|
private Thread thread;
|
|
|
|
private String error = null;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void create() {
|
|
|
|
super.create();
|
2014-11-16 01:52:02 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
String text = "";
|
|
|
|
switch (mode) {
|
|
|
|
case DESCEND:
|
|
|
|
text = TXT_DESCENDING;
|
|
|
|
break;
|
|
|
|
case ASCEND:
|
|
|
|
text = TXT_ASCENDING;
|
|
|
|
break;
|
|
|
|
case CONTINUE:
|
|
|
|
text = TXT_LOADING;
|
|
|
|
break;
|
|
|
|
case RESURRECT:
|
|
|
|
text = TXT_RESURRECTING;
|
|
|
|
break;
|
|
|
|
case RETURN:
|
|
|
|
text = TXT_RETURNING;
|
|
|
|
break;
|
|
|
|
case FALL:
|
|
|
|
text = TXT_FALLING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = PixelScene.createText( text, 9 );
|
|
|
|
message.measure();
|
|
|
|
message.x = (Camera.main.width - message.width()) / 2;
|
|
|
|
message.y = (Camera.main.height - message.height()) / 2;
|
|
|
|
add( message );
|
|
|
|
|
|
|
|
phase = Phase.FADE_IN;
|
|
|
|
timeLeft = TIME_TO_FADE;
|
2014-11-16 01:52:02 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
thread = new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Generator.reset();
|
2014-11-16 01:52:02 +00:00
|
|
|
|
|
|
|
Sample.INSTANCE.load(
|
2014-07-27 13:39:07 +00:00
|
|
|
Assets.SND_OPEN,
|
|
|
|
Assets.SND_UNLOCK,
|
|
|
|
Assets.SND_ITEM,
|
2014-11-16 01:52:02 +00:00
|
|
|
Assets.SND_DEWDROP,
|
|
|
|
Assets.SND_HIT,
|
2014-07-27 13:39:07 +00:00
|
|
|
Assets.SND_MISS,
|
|
|
|
Assets.SND_STEP,
|
|
|
|
Assets.SND_WATER,
|
|
|
|
Assets.SND_DESCEND,
|
|
|
|
Assets.SND_EAT,
|
|
|
|
Assets.SND_READ,
|
|
|
|
Assets.SND_LULLABY,
|
|
|
|
Assets.SND_DRINK,
|
|
|
|
Assets.SND_SHATTER,
|
|
|
|
Assets.SND_ZAP,
|
|
|
|
Assets.SND_LIGHTNING,
|
|
|
|
Assets.SND_LEVELUP,
|
|
|
|
Assets.SND_DEATH,
|
|
|
|
Assets.SND_CHALLENGE,
|
|
|
|
Assets.SND_CURSED,
|
|
|
|
Assets.SND_EVOKE,
|
|
|
|
Assets.SND_TRAP,
|
|
|
|
Assets.SND_TOMB,
|
|
|
|
Assets.SND_ALERT,
|
|
|
|
Assets.SND_MELD,
|
|
|
|
Assets.SND_BOSS,
|
|
|
|
Assets.SND_BLAST,
|
|
|
|
Assets.SND_PLANT,
|
|
|
|
Assets.SND_RAY,
|
|
|
|
Assets.SND_BEACON,
|
|
|
|
Assets.SND_TELEPORT,
|
|
|
|
Assets.SND_CHARMS,
|
|
|
|
Assets.SND_MASTERY,
|
|
|
|
Assets.SND_PUFF,
|
|
|
|
Assets.SND_ROCKS,
|
|
|
|
Assets.SND_BURNING,
|
|
|
|
Assets.SND_FALLING,
|
|
|
|
Assets.SND_GHOST,
|
|
|
|
Assets.SND_SECRET,
|
|
|
|
Assets.SND_BONES );
|
2014-11-16 01:52:02 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
switch (mode) {
|
|
|
|
case DESCEND:
|
|
|
|
descend();
|
|
|
|
break;
|
|
|
|
case ASCEND:
|
|
|
|
ascend();
|
|
|
|
break;
|
|
|
|
case CONTINUE:
|
|
|
|
restore();
|
|
|
|
break;
|
|
|
|
case RESURRECT:
|
|
|
|
resurrect();
|
|
|
|
break;
|
|
|
|
case RETURN:
|
|
|
|
returnTo();
|
|
|
|
break;
|
|
|
|
case FALL:
|
|
|
|
fall();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Dungeon.depth % 5) == 0) {
|
|
|
|
Sample.INSTANCE.load( Assets.SND_BOSS );
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
|
|
|
error = ERR_FILE_NOT_FOUND;
|
2014-11-16 01:52:02 +00:00
|
|
|
|
|
|
|
} catch (IOException e ) {
|
|
|
|
|
2014-11-25 06:15:11 +00:00
|
|
|
error = ERR_IO;
|
2014-11-16 01:52:02 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (phase == Phase.STATIC && error == null) {
|
|
|
|
phase = Phase.FADE_OUT;
|
|
|
|
timeLeft = TIME_TO_FADE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
thread.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
super.update();
|
|
|
|
|
|
|
|
float p = timeLeft / TIME_TO_FADE;
|
|
|
|
|
|
|
|
switch (phase) {
|
|
|
|
|
|
|
|
case FADE_IN:
|
|
|
|
message.alpha( 1 - p );
|
|
|
|
if ((timeLeft -= Game.elapsed) <= 0) {
|
|
|
|
if (!thread.isAlive() && error == null) {
|
|
|
|
phase = Phase.FADE_OUT;
|
|
|
|
timeLeft = TIME_TO_FADE;
|
|
|
|
} else {
|
|
|
|
phase = Phase.STATIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FADE_OUT:
|
|
|
|
message.alpha( p );
|
|
|
|
|
|
|
|
if (mode == Mode.CONTINUE || (mode == Mode.DESCEND && Dungeon.depth == 1)) {
|
|
|
|
Music.INSTANCE.volume( p );
|
|
|
|
}
|
|
|
|
if ((timeLeft -= Game.elapsed) <= 0) {
|
|
|
|
Game.switchScene( GameScene.class );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATIC:
|
|
|
|
if (error != null) {
|
|
|
|
add( new WndError( error ) {
|
|
|
|
public void onBackPressed() {
|
|
|
|
super.onBackPressed();
|
|
|
|
Game.switchScene( StartScene.class );
|
|
|
|
};
|
|
|
|
} );
|
2014-10-18 08:56:57 +00:00
|
|
|
error = null;
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-16 01:52:02 +00:00
|
|
|
|
|
|
|
private void descend() throws IOException {
|
2014-10-22 00:47:40 +00:00
|
|
|
|
|
|
|
Level level;
|
|
|
|
ArrayList<Item> fallingItems = new ArrayList<Item>();
|
|
|
|
|
|
|
|
Actor.fixTime();
|
2014-07-27 13:39:07 +00:00
|
|
|
if (Dungeon.hero == null) {
|
|
|
|
Dungeon.init();
|
|
|
|
if (noStory) {
|
|
|
|
Dungeon.chapters.add( WndStory.ID_SEWERS );
|
|
|
|
noStory = false;
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-05 14:42:41 +00:00
|
|
|
level = Dungeon.level;
|
|
|
|
|
|
|
|
fallingItems = level.fallingItems;
|
|
|
|
level.fallingItems = new ArrayList<Item>();
|
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
Dungeon.saveLevel();
|
|
|
|
}
|
2014-10-22 00:47:40 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
if (Dungeon.depth >= Statistics.deepestFloor) {
|
|
|
|
level = Dungeon.newLevel();
|
|
|
|
} else {
|
|
|
|
Dungeon.depth++;
|
|
|
|
level = Dungeon.loadLevel( Dungeon.hero.heroClass );
|
|
|
|
}
|
2014-10-22 00:47:40 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
Dungeon.switchLevel( level, level.entrance );
|
2014-10-22 00:47:40 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
|
2014-11-16 01:52:02 +00:00
|
|
|
private void fall() throws IOException {
|
2014-10-22 00:47:40 +00:00
|
|
|
|
|
|
|
Level level = Dungeon.level;
|
|
|
|
|
|
|
|
ArrayList<Item> fallingItems = level.fallingItems;
|
|
|
|
level.fallingItems = new ArrayList<Item>();
|
|
|
|
|
|
|
|
Actor.fixTime();
|
2014-07-27 13:39:07 +00:00
|
|
|
Dungeon.saveLevel();
|
2014-10-22 00:47:40 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
if (Dungeon.depth >= Statistics.deepestFloor) {
|
|
|
|
level = Dungeon.newLevel();
|
|
|
|
} else {
|
|
|
|
Dungeon.depth++;
|
|
|
|
level = Dungeon.loadLevel( Dungeon.hero.heroClass );
|
|
|
|
}
|
2014-10-22 00:47:40 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
Dungeon.switchLevel( level, fallIntoPit ? level.pitCell() : level.randomRespawnCell() );
|
|
|
|
}
|
|
|
|
|
2014-11-16 01:52:02 +00:00
|
|
|
private void ascend() throws IOException {
|
2014-07-27 13:39:07 +00:00
|
|
|
Actor.fixTime();
|
|
|
|
|
|
|
|
Dungeon.saveLevel();
|
|
|
|
Dungeon.depth--;
|
|
|
|
Level level = Dungeon.loadLevel( Dungeon.hero.heroClass );
|
|
|
|
Dungeon.switchLevel( level, level.exit );
|
|
|
|
}
|
|
|
|
|
2014-11-16 01:52:02 +00:00
|
|
|
private void returnTo() throws IOException {
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
Actor.fixTime();
|
|
|
|
|
|
|
|
Dungeon.saveLevel();
|
|
|
|
Dungeon.depth = returnDepth;
|
|
|
|
Level level = Dungeon.loadLevel( Dungeon.hero.heroClass );
|
|
|
|
Dungeon.switchLevel( level, Level.resizingNeeded ? level.adjustPos( returnPos ) : returnPos );
|
|
|
|
}
|
|
|
|
|
2014-11-16 01:52:02 +00:00
|
|
|
private void restore() throws IOException {
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
Actor.fixTime();
|
|
|
|
|
|
|
|
Dungeon.loadGame( StartScene.curClass );
|
|
|
|
if (Dungeon.depth == -1) {
|
|
|
|
Dungeon.depth = Statistics.deepestFloor;
|
|
|
|
Dungeon.switchLevel( Dungeon.loadLevel( StartScene.curClass ), -1 );
|
|
|
|
} else {
|
|
|
|
Level level = Dungeon.loadLevel( StartScene.curClass );
|
|
|
|
Dungeon.switchLevel( level, Level.resizingNeeded ? level.adjustPos( Dungeon.hero.pos ) : Dungeon.hero.pos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-16 01:52:02 +00:00
|
|
|
private void resurrect() throws IOException {
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
Actor.fixTime();
|
|
|
|
|
2014-10-13 17:28:15 +00:00
|
|
|
if (Dungeon.level.locked) {
|
2014-07-27 13:39:07 +00:00
|
|
|
Dungeon.hero.resurrect( Dungeon.depth );
|
|
|
|
Dungeon.depth--;
|
|
|
|
Level level = Dungeon.newLevel(/* true */);
|
|
|
|
Dungeon.switchLevel( level, level.entrance );
|
|
|
|
} else {
|
|
|
|
Dungeon.hero.resurrect( -1 );
|
|
|
|
Dungeon.resetLevel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onBackPressed() {
|
|
|
|
}
|
|
|
|
}
|