Java Code Examples for com.watabou.noosa.Game#switchScene()

The following examples show how to use com.watabou.noosa.Game#switchScene() . 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: Hero.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
private boolean actDescend( HeroAction.Descend action ) {
	int stairs = action.dst;
	if (pos == stairs) {
		
		curAction = null;

		Buff buff = buff(TimekeepersHourglass.timeFreeze.class);
		if (buff != null) buff.detach();
		buff = Dungeon.hero.buff(Swiftthistle.TimeBubble.class);
		if (buff != null) buff.detach();
		
		InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
		Game.switchScene( InterlevelScene.class );

		return false;

	} else if (getCloser( stairs )) {

		return true;

	} else {
		ready();
		return false;
	}
}
 
Example 2
Source File: DistortionTrap.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void activate() {
	InterlevelScene.returnDepth = Dungeon.depth;
	Belongings belongings = Dungeon.hero.belongings;
	
	for (Notes.Record rec : Notes.getRecords()){
		if (rec.depth() == Dungeon.depth){
			Notes.remove(rec);
		}
	}
	
	for (Item i : belongings){
		if (i instanceof LloydsBeacon && ((LloydsBeacon) i).returnDepth == Dungeon.depth)
				((LloydsBeacon) i).returnDepth = -1;
	}

	InterlevelScene.mode = InterlevelScene.Mode.RESET;
	Game.switchScene(InterlevelScene.class);
}
 
Example 3
Source File: AlchemistsToolkit.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(Hero hero, String action ) {

	super.execute(hero, action);

	if (action.equals(AC_BREW)){
		if (!isEquipped(hero))                                          GLog.i( Messages.get(this, "need_to_equip") );
		else if (cursed)                                                GLog.w( Messages.get(this, "cursed") );
		else if (!alchemyReady)                                         GLog.i( Messages.get(this, "not_ready") );
		else if (hero.visibleEnemies() > hero.mindVisionEnemies.size()) GLog.i( Messages.get(this, "enemy_near") );
		else {
			
			AlchemyScene.setProvider(hero.buff(kitEnergy.class));
			Game.switchScene(AlchemyScene.class);
		}
		
	}
}
 
Example 4
Source File: Amulet.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private void showAmuletScene( boolean showText ) {
	try {
		Dungeon.saveAll();
		AmuletScene.noText = !showText;
		Game.switchScene( AmuletScene.class );
	} catch (IOException e) {
	}
}
 
Example 5
Source File: Amulet.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private void showAmuletScene( boolean showText ) {
	try {
		Dungeon.saveAll();
		AmuletScene.noText = !showText;
		Game.switchScene( AmuletScene.class );
	} catch (IOException e) {
	}
}
 
Example 6
Source File: StartScene.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
private void startNewGame() {

		Dungeon.hero = null;
		InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
		
		if (YetAnotherPixelDungeon.intro()) {
			YetAnotherPixelDungeon.intro(false);
			Game.switchScene( IntroScene.class );
		} else {
			Game.switchScene( InterlevelScene.class );
		}	
	}
 
Example 7
Source File: GameControl.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@LuaInterface
static public void startNewGame(String className, int difficulty, boolean testMode) {
    Dungeon.setDifficulty(difficulty);
    Dungeon.hero = null;
    Dungeon.heroClass = HeroClass.valueOf(className);

    if(testMode) {
        EventCollector.disable();
    }

    Map<String,String> resDesc = new HashMap<>();
    resDesc.put("class",className);
    resDesc.put("mod", RemixedDungeon.activeMod());
    resDesc.put("difficulty",  String.valueOf(difficulty));

    EventCollector.logEvent("game", resDesc);

    Logbook.logbookEntries.clear();    // Clear the log book before starting a new game
    ServiceManNPC.resetLimit();

    if (RemixedDungeon.intro()) {
        RemixedDungeon.intro(false);
        Game.switchScene(IntroScene.class);
    } else {
        InterlevelScene.Do(InterlevelScene.Mode.DESCEND);
    }
}
 
Example 8
Source File: InterlevelScene.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
static public void Do(InterlevelScene.Mode mode) {

        if(Game.scene() instanceof GameScene && Dungeon.level!=null && Dungeon.hero!=null) { // not game start
            Dungeon.hero.getSprite().completeForce();
            for(Mob mob:Dungeon.level.getCopyOfMobsArray()) {
                mob.getSprite().completeForce();
            }
        }

        InterlevelScene.mode = mode;
        Game.switchScene(InterlevelScene.class);
    }
 
Example 9
Source File: Hero.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
private boolean actAscend( HeroAction.Ascend action ) {
	int stairs = action.dst;


	if (rooted){
		Camera.main.shake( 1, 1f );
		ready();
		return false;
	//there can be multiple entrance tiles, so descend on any of them
	//TODO this is slightly brittle, it assumes there are no disjointed sets of entrance tiles
	} else if (Dungeon.level.map[pos] == Terrain.ENTRANCE) {
		
		if (Dungeon.depth == 1) {
			
			if (belongings.getItem( Amulet.class ) == null) {
				Game.runOnRenderThread(new Callback() {
					@Override
					public void call() {
						GameScene.show( new WndMessage( Messages.get(Hero.this, "leave") ) );
					}
				});
				ready();
			} else {
				Badges.silentValidateHappyEnd();
				Dungeon.win( Amulet.class );
				Dungeon.deleteGame( GamesInProgress.curSlot, true );
				Game.switchScene( SurfaceScene.class );
			}
			
		} else {
			
			curAction = null;

			Buff buff = buff(TimekeepersHourglass.timeFreeze.class);
			if (buff != null) buff.detach();
			buff = Dungeon.hero.buff(Swiftthistle.TimeBubble.class);
			if (buff != null) buff.detach();

			InterlevelScene.mode = InterlevelScene.Mode.ASCEND;
			Game.switchScene( InterlevelScene.class );
		}

		return false;

	} else if (getCloser( stairs )) {

		return true;

	} else {
		ready();
		return false;
	}
}
 
Example 10
Source File: AmuletScene.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onBackPressed() {
	InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
	Game.switchScene( InterlevelScene.class );
}
 
Example 11
Source File: AmuletScene.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void create() {
	super.create();
	
	BitmapTextMultiline text = null;
	if (!noText) {
		text = createMultiline( TXT, 8 );
		text.maxWidth = WIDTH;
		text.measure();
		add( text );
	}
	
	amulet = new Image( Assets.AMULET );
	add( amulet );
	
	RedButton btnExit = new RedButton( TXT_EXIT ) {
		@Override
		protected void onClick() {
			Dungeon.win( ResultDescriptions.WIN );
			Dungeon.deleteGame( Dungeon.hero.heroClass, true );
			Game.switchScene( noText ? TitleScene.class : RankingsScene.class );
		}
	};
	btnExit.setSize( WIDTH, BTN_HEIGHT );
	add( btnExit );
	
	RedButton btnStay = new RedButton( TXT_STAY ) {
		@Override
		protected void onClick() {
			onBackPressed();
		}
	};
	btnStay.setSize( WIDTH, BTN_HEIGHT );
	add( btnStay );
	
	float height;
	if (noText) {
		height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
		
		amulet.x = align( (Camera.main.width - amulet.width) / 2 );
		amulet.y = align( (Camera.main.height - height) / 2 );
		
		btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP );
		btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
		
	} else {
		height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
		
		amulet.x = align( (Camera.main.width - amulet.width) / 2 );
		amulet.y = align( (Camera.main.height - height) / 2 );
		
		text.x =  align( (Camera.main.width - text.width()) / 2 );
		text.y = amulet.y + amulet.height + LARGE_GAP;
		
		btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, text.y + text.height() + LARGE_GAP );
		btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
	}

	new Flare( 8, 48 ).color( 0xFFDDBB, true ).show( amulet, 0 ).angularSpeed = +30;
	
	fadeIn();
}
 
Example 12
Source File: WndResurrect.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public WndResurrect( final Ankh ankh, Object causeOfDeath ) {
	
	super();
	
	instance = this;
	WndResurrect.causeOfDeath = causeOfDeath;
	
	IconTitle titlebar = new IconTitle();
	titlebar.icon( new ItemSprite( ankh.image(), null ) );
	titlebar.label( ankh.name() );
	titlebar.setRect( 0, 0, WIDTH, 0 );
	add( titlebar );
	
	BitmapTextMultiline message = PixelScene.createMultiline( TXT_MESSAGE, 6 );
	message.maxWidth = WIDTH;
	message.measure();
	message.y = titlebar.bottom() + GAP;
	add( message );
	
	RedButton btnYes = new RedButton( TXT_YES ) {
		@Override
		protected void onClick() {
			hide();
			
			Statistics.ankhsUsed++;
			
			InterlevelScene.mode = InterlevelScene.Mode.RESURRECT;
			Game.switchScene( InterlevelScene.class );
		}
	};
	btnYes.setRect( 0, message.y + message.height() + GAP, WIDTH, BTN_HEIGHT );
	add( btnYes );
	
	RedButton btnNo = new RedButton( TXT_NO ) {
		@Override
		protected void onClick() {
			hide();
			
			Rankings.INSTANCE.submit( false );
			Hero.reallyDie( WndResurrect.causeOfDeath );
		}
	};
	btnNo.setRect( 0, btnYes.bottom() + GAP, WIDTH, BTN_HEIGHT );
	add( btnNo );
	
	resize( WIDTH, (int)btnNo.bottom() );
}
 
Example 13
Source File: AmuletScene.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onBackPressed() {
	InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
	Game.switchScene( InterlevelScene.class );
}
 
Example 14
Source File: WndStartGame.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public WndStartGame(final int slot){
	
	Badges.loadGlobal();
	Journal.loadGlobal();
	
	RenderedTextBlock title = PixelScene.renderTextBlock(Messages.get(this, "title"), 12 );
	title.hardlight(Window.TITLE_COLOR);
	title.setPos( (WIDTH - title.width())/2f, 3);
	PixelScene.align(title);
	add(title);
	
	float heroBtnSpacing = (WIDTH - 4*HeroBtn.WIDTH)/5f;
	
	float curX = heroBtnSpacing;
	for (HeroClass cl : HeroClass.values()){
		HeroBtn button = new HeroBtn(cl);
		button.setRect(curX, title.height() + 7, HeroBtn.WIDTH, HeroBtn.HEIGHT);
		curX += HeroBtn.WIDTH + heroBtnSpacing;
		add(button);
	}
	
	ColorBlock separator = new ColorBlock(1, 1, 0xFF222222);
	separator.size(WIDTH, 1);
	separator.x = 0;
	separator.y = title.bottom() + 6 + HeroBtn.HEIGHT;
	add(separator);
	
	HeroPane ava = new HeroPane();
	ava.setRect(20, separator.y + 2, WIDTH-30, 80);
	add(ava);
	
	RedButton start = new RedButton(Messages.get(this, "start")){
		@Override
		protected void onClick() {
			if (GamesInProgress.selectedClass == null) return;
			
			super.onClick();
			
			GamesInProgress.curSlot = slot;
			Dungeon.hero = null;
			ActionIndicator.action = null;
			InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
			
			if (SPDSettings.intro()) {
				SPDSettings.intro( false );
				Game.switchScene( IntroScene.class );
			} else {
				Game.switchScene( InterlevelScene.class );
			}
		}
		
		@Override
		public void update() {
			if( !visible && GamesInProgress.selectedClass != null){
				visible = true;
			}
			super.update();
		}
	};
	start.visible = false;
	start.setRect(0, HEIGHT - 20, WIDTH, 20);
	add(start);
	
	if (DeviceCompat.isDebug() || Badges.isUnlocked(Badges.Badge.VICTORY)){
		IconButton challengeButton = new IconButton(
				Icons.get( SPDSettings.challenges() > 0 ? Icons.CHALLENGE_ON :Icons.CHALLENGE_OFF)){
			@Override
			protected void onClick() {
				ShatteredPixelDungeon.scene().add(new WndChallenges(SPDSettings.challenges(), true) {
					public void onBackPressed() {
						super.onBackPressed();
						icon( Icons.get( SPDSettings.challenges() > 0 ?
								Icons.CHALLENGE_ON :Icons.CHALLENGE_OFF ) );
					}
				} );
			}
			
			@Override
			public void update() {
				if( !visible && GamesInProgress.selectedClass != null){
					visible = true;
				}
				super.update();
			}
		};
		challengeButton.setRect(WIDTH - 20, HEIGHT - 20, 20, 20);
		challengeButton.visible = false;
		add(challengeButton);
		
	} else {
		Dungeon.challenges = 0;
		SPDSettings.challenges(0);
	}
	
	resize(WIDTH, HEIGHT);
	
}
 
Example 15
Source File: LoadSaveScene.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onBackPressed() {
    InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
    Game.switchScene( InterlevelScene.class );
}
 
Example 16
Source File: InterlevelScene.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void update() {
	super.update();

	waitingTime += Game.elapsed;
	
	float p = timeLeft / fadeTime;
	
	switch (phase) {
	
	case FADE_IN:
		message.alpha( 1 - p );
		if ((timeLeft -= Game.elapsed) <= 0) {
			if (!thread.isAlive() && error == null) {
				phase = Phase.FADE_OUT;
				timeLeft = fadeTime;
			} else {
				phase = Phase.STATIC;
			}
		}
		break;
		
	case FADE_OUT:
		message.alpha( p );
		
		if ((timeLeft -= Game.elapsed) <= 0) {
			Game.switchScene( GameScene.class );
			thread = null;
			error = null;
		}
		break;
		
	case STATIC:
		if (error != null) {
			String errorMsg;
			if (error instanceof FileNotFoundException)     errorMsg = Messages.get(this, "file_not_found");
			else if (error instanceof IOException)          errorMsg = Messages.get(this, "io_error");
			else if (error.getMessage() != null &&
					error.getMessage().equals("old save")) errorMsg = Messages.get(this, "io_error");

			else throw new RuntimeException("fatal error occured while moving between floors. " +
						"Seed:" + Dungeon.seed + " depth:" + Dungeon.depth, error);

			add( new WndError( errorMsg ) {
				public void onBackPressed() {
					super.onBackPressed();
					Game.switchScene( StartScene.class );
				}
			} );
			thread = null;
			error = null;
		} else if (thread != null && (int)waitingTime == 10){
			waitingTime = 11f;
			String s = "";
			for (StackTraceElement t : thread.getStackTrace()){
				s += "\n";
				s += t.toString();
			}
			ShatteredPixelDungeon.reportException(
					new RuntimeException("waited more than 10 seconds on levelgen. " +
							"Seed:" + Dungeon.seed + " depth:" + Dungeon.depth + " trace:" +
							s)
			);
		}
		break;
	}
}
 
Example 17
Source File: WelcomeScene.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void create() {
	super.create();

	String[] upds = {
			Game.getVar(R.string.Welcome_Text_29_1),
			Game.getVar(R.string.Welcome_Text_29_2),
			Game.getVar(R.string.Welcome_Text_29_3),
			Game.getVar(R.string.Welcome_Text_29_4),
			Game.getVar(R.string.Welcome_Text_29_5)
	};

	int displayUpdates = Math.min(upds.length, 5);

	Text[] updTexts = new Text[displayUpdates];

	for (int i = 0; i < displayUpdates; i++) {
		updTexts[i] = createMultiline(GuiProperties.regularFontSize());
	}

	Text title = createMultiline(Game.getVar(R.string.Welcome_Title), GuiProperties.bigTitleFontSize());

	int w = Camera.main.width;
	int h = Camera.main.height;

	int pw = w - 10;

	title.maxWidth(pw);

	title.x = align((w - title.width()) / 2);
	title.y = align(8);
	add(title);

	NinePatch panel = Chrome.get(Chrome.Type.WINDOW);

	panel.x = (w - pw) / 2;
	panel.y = title.y + title.height() + GAP * 2;
	int ph = (int) (h - panel.y - 22);

	panel.size(pw, ph);

	add(panel);

	ScrollPane list = new ScrollPane(new Component());
	add(list);
	list.setRect(panel.x + panel.marginLeft(), panel.y + panel.marginTop(), panel.innerWidth(),
			panel.innerHeight());
	list.scrollTo(0, 0);

	Component content = list.content();
	content.clear();

	float yPos = 0;
	for (int i = 0; i < displayUpdates; i++) {
		updTexts[i].maxWidth((int) panel.innerWidth());
		updTexts[i].text(upds[upds.length - i - 1]);

		updTexts[i].setPos(0, yPos);
		yPos += updTexts[i].height() + GAP;
		content.add(updTexts[i]);
	}

	content.setSize(panel.innerWidth(), yPos);

	RedButton okay = new RedButton(Game.getVar(R.string.Welcome_Ok)) {
		@Override
		protected void onClick() {
			RemixedDungeon.version(Game.versionCode);
			RemixedDungeon.versionString(Game.version);

			if (Preferences.INSTANCE.getInt(Preferences.KEY_COLLECT_STATS, 1) == 0) {
				Game.switchScene(AllowStatisticsCollectionScene.class);
			} else {
				Game.switchScene(TitleScene.class);
			}
		}
	};

	okay.setRect((w - pw) / 2, h - 22, pw, 18);
	add(okay);

	Archs archs = new Archs();
	archs.setSize(Camera.main.width, Camera.main.height);
	addToBack(archs);

	fadeIn();
}
 
Example 18
Source File: AmuletScene.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void create() {
	super.create();
	
	Text text = null;
	if (!noText) {
		text = createMultiline( Game.getVar(R.string.AmuletScene_Txt), GuiProperties.regularFontSize() );
		text.maxWidth(WIDTH);
		add( text );
	}
	
	amulet = new Image( Assets.AMULET );
	add( amulet );
	
	RedButton btnExit = new RedButton( Game.getVar(R.string.AmuletScene_Exit) ) {
		@Override
		protected void onClick() {
			Dungeon.win( ResultDescriptions.getDescription(ResultDescriptions.Reason.WIN), Rankings.gameOver.WIN_AMULET );
			Dungeon.gameOver();
			Game.switchScene( noText ? TitleScene.class : RankingsScene.class );
		}
	};
	btnExit.setSize( WIDTH, BTN_HEIGHT );
	add( btnExit );
	
	RedButton btnStay = new RedButton( Game.getVar(R.string.AmuletScene_Stay) ) {
		@Override
		protected void onClick() {
			onBackPressed();
		}
	};
	btnStay.setSize( WIDTH, BTN_HEIGHT );
	add( btnStay );
	
	float height;
	if (noText) {
		height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
		
		amulet.x = align( (Camera.main.width - amulet.width) / 2 );
		amulet.y = align( (Camera.main.height - height) / 2 );
		
		btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP );
		btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
		
	} else {
		height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
		
		amulet.x = align( (Camera.main.width - amulet.width) / 2 );
		amulet.y = align( (Camera.main.height - height) / 2 );
		
		text.x =  align( (Camera.main.width - text.width()) / 2 );
		text.y = amulet.y + amulet.height + LARGE_GAP;
		
		btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, text.y + text.height() + LARGE_GAP );
		btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
	}

	new Flare( 8, 48 ).color( 0xFFDDBB, true ).show( amulet, 0 ).angularSpeed = +30;
	
	fadeIn();
}
 
Example 19
Source File: AmuletScene.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onBackPressed() {
	InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
	Game.switchScene( InterlevelScene.class );
}
 
Example 20
Source File: Hero.java    From remixed-dungeon with GNU General Public License v3.0 2 votes vote down vote up
private boolean actAscend(CharAction.Ascend action) {

		int stairs = action.dst;
		if (getPos() == stairs && getPos() == Dungeon.level.entrance) {

			Position nextLevel = DungeonGenerator.ascend(Dungeon.currentPosition());

			if (nextLevel.levelId.equals("0")) {

				if (belongings.getItem(Amulet.class) == null) {
					GameScene.show(new WndMessage(Game.getVar(R.string.Hero_Leave)));
					readyAndIdle();
				} else {
					Dungeon.win(ResultDescriptions.getDescription(ResultDescriptions.Reason.WIN), Rankings.gameOver.WIN_HAPPY);

					Dungeon.gameOver();

					Game.switchScene(SurfaceScene.class);
				}

			} else {

				clearActions();

				if (!Dungeon.level.isSafe()) {
					hunger().satisfy(-Hunger.STARVING / 10);
				}

				InterlevelScene.Do(InterlevelScene.Mode.ASCEND);
			}

			return false;

		} else if (getCloser(stairs)) {

			return true;

		} else {
			readyAndIdle();
			return false;
		}
	}