/// <summary> /// Exit the screen after a tap gesture /// </summary> /// <param name="input"></param> public override void HandleInput(GameTime gameTime, InputState input) { if (!isLoading) { PlayerIndex player; // Handle touch input if (input.Gestures.Count > 0) { if (input.Gestures[0].GestureType == GestureType.Tap) { LoadResources(); } } else if (input.IsNewKeyPress(Keys.Escape, ControllingPlayer, out player)) { foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(new BackgroundScreen("titleScreen"), null); ScreenManager.AddScreen(new MainMenuScreen(), PlayerIndex.One); } else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) || input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player)) { LoadResources(); } } base.HandleInput(gameTime, input); }
/// <summary> /// A handler invoked after the user has enter his name. /// </summary> /// <param name="result"></param> private void AfterPlayerEnterName(IAsyncResult result) { // Gets the name entered string playerName = Guide.EndShowKeyboardInput(result); if (!string.IsNullOrEmpty(playerName)) { // Ensure that it is valid if (playerName != null && playerName.Length > 15) { playerName = playerName.Substring(0, 15); } // Puts it in high score HighScoreScreen.PutHighScore(playerName, GameplayScreen.FinalScore); HighScoreScreen.HighScoreChanged(); } // Moves to the next screen foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null); ScreenManager.AddScreen(new HighScoreScreen(), null); }
/// <summary> /// Screen update logic /// </summary> /// <param name="gameTime"></param> /// <param name="otherScreenHasFocus"></param> /// <param name="coveredByOtherScreen"></param> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { // If necessary, load the highscore. Remember that calling LoadHighscores multiple times does not have // and adverse effect. Highscore will only be loaded once. if (!HighScoreScreen.HighscoreLoaded) { HighScoreScreen.LoadHighscores(); } // If additional thread is running, do nothing else if (null != thread) { // If additional thread finished loading and the screen is not exiting if (thread.ThreadState == ThreadState.Stopped && !IsExiting) { // Move on to the game play screen once highscore data is loaded foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(gameplayScreen, null); } } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }
/// <summary> /// Starts new level or exit to High Score /// </summary> /// <param name="input"></param> private void StartNewLevelOrExit(InputState input) { // If there is no next level - go to high score screen if (!difficultyMode.HasValue) { // If is in high score, gets is name if (GameplayScreen.FinalScore != 0 && HighScoreScreen.IsInHighscores(GameplayScreen.FinalScore)) { Guide.BeginShowKeyboardInput(PlayerIndex.One, "Player Name", "What is your name (max 15 characters)?", "Player", AfterPlayerEnterName, null); } else { foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null); ScreenManager.AddScreen(new HighScoreScreen(), null); } } // If not already loading else if (!isLoading) { // Start loading the resources in an additional thread thread = new Thread(new ThreadStart(gameplayScreen.LoadAssets)); isLoading = true; thread.Start(); } }
/// <summary> /// Respond to "Quit Game" Item Selection /// </summary> /// <param name="playerIndex"></param> protected override void OnCancel(PlayerIndex playerIndex) { foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(new BackgroundScreen("titleScreen"), null); ScreenManager.AddScreen(new MainMenuScreen(), null); }
/// <summary> /// Respond to "Return" Item Selection /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ReturnGameMenuEntrySelected(object sender, EventArgs e) { AudioManager.PauseResumeSounds(true); foreach (GameScreen screen in ScreenManager.GetScreens()) { if (!(screen is GameplayScreen)) { screen.ExitScreen(); } } }
/// <summary> /// Respond to "Play" Item Selection /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void StartGameMenuEntrySelected(object sender, EventArgs e) { foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(new BackgroundScreen("Instructions"), null); ScreenManager.AddScreen(new LoadingAndInstructionScreen(), null); AudioManager.StopSound("MenuMusic_Loop"); }
/// <summary> /// Starts new level or exit to High Score /// </summary> /// <param name="input"></param> private void StartNewLevelOrExit(InputState input) { // If there is no next level - go to high score screen if (!difficultyMode.HasValue) { // If is in high score, gets is name if (GameplayScreen.FinalScore != 0 && HighScoreScreen.IsInHighscores(GameplayScreen.FinalScore)) { Guide.BeginShowKeyboardInput(PlayerIndex.One, "Player Name", "What is your name (max 15 characters)?", "Player", AfterPlayerEnterName, null); } else { foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null); ScreenManager.AddScreen(new HighScoreScreen(), null); } } // If not already loading else if (!isLoading) { #if MONOMAC // Start loading the resources on main thread // If not then all sorts of errors happen for // AutoReleasPools and OpenGL does not handle // multiple thread to well when using Thread MonoMac.AppKit.NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate { gameplayScreen.LoadAssets(); isLoading = false; assetsLoaded = true; }); #else // Start loading the resources in an additional thread thread = new Thread(new ThreadStart(gameplayScreen.LoadAssets)); isLoading = true; thread.Start(); #endif } }
/// <summary> /// Respond to "Play" Item Selection /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void StartGameMenuEntrySelected(object sender, EventArgs e) { foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } #if WINDOWS_PHONE ScreenManager.AddScreen(new BackgroundScreen("Instructions"), null); #elif XBOX ScreenManager.AddScreen(new BackgroundScreen("InstructionsXbox"), null); #else ScreenManager.AddScreen(new BackgroundScreen("InstructionsPC"), null); #endif ScreenManager.AddScreen(new LoadingAndInstructionScreen(), null); AudioManager.StopSound("MenuMusic_Loop"); }
/// <summary> /// Update the screen /// </summary> /// <param name="gameTime">Game time information.</param> /// <param name="otherScreenHasFocus">Whether another screen has the focus.</param> /// <param name="coveredByOtherScreen">Whether this screen is covered by another.</param> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { // If null don't do anything if (null != thread) { // If we finishedloading the assets, add the game play screen if (thread.ThreadState == ThreadState.Stopped) { // Exit all the screen foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } // Add the gameplay screen if (difficultyMode.HasValue) { ScreenManager.AddScreen(gameplayScreen, null); } } } else if (assetsLoaded) { // Screen is not exiting if (!IsExiting) { // Move on to the game play screen once highscore data is loaded foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } // Add the gameplay screen if (difficultyMode.HasValue) { ScreenManager.AddScreen(gameplayScreen, null); } } } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }
/// <summary> /// Screen update logic /// </summary> /// <param name="gameTime"></param> /// <param name="otherScreenHasFocus"></param> /// <param name="coveredByOtherScreen"></param> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { // If additional thread is running, do nothing if (null != thread) { // If additional thread finished loading and the screen is not // exiting if (thread.ThreadState == ThreadState.Stopped && !IsExiting) { // Move on to the game play screen foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(gameplayScreen, null); } } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }