public override void LoadContent() { instructionsTexture = ScreenManager.Game.Content.Load <Texture2D>("Textures/Backgrounds/Instructions"); loadingTexture = ScreenManager.Game.Content.Load <Texture2D>("Textures/Backgrounds/loading"); ninjaTexture = ScreenManager.Game.Content.Load <Texture2D>("Textures/ninja"); titleTexture = ScreenManager.Game.Content.Load <Texture2D>("Textures/title"); // If necessary, load the high-score data if (!HighScoreScreen.HighscoreLoaded) { HighScoreScreen.LoadHighscores(); } AudioManager.LoadSounds(); AudioManager.LoadMusic(); // We want to find the widest menu entry for (int i = 0; i < MenuEntries.Count; i++) { float entryWidth = ScreenManager.Font.MeasureString(MenuEntries[i].Text).X; if (maxEntryWidth < entryWidth) { maxEntryWidth = entryWidth; } } base.LoadContent(); }
/// <summary> /// Performs necessary update logic. /// </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) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); // Save the high-score when exiting the game if (isExiting) { if (!HighScoreScreen.HighscoreSaved) { HighScoreScreen.SaveHighscore(); } else { isExiting = false; // When exiting intentionally, clear the saved game data NinjAcademyGame.CleanIsolatedStorage(); ScreenManager.Game.Exit(); return; } } // Move on to the instruction screen if necessary if (isMovingToLoading) { foreach (GameScreen screen in ScreenManager.GetScreens()) { screen.ExitScreen(); } ScreenManager.AddScreen(new BackgroundScreen("Instructions"), null); ScreenManager.AddScreen(new LoadingScreen(instructionsTexture, loadingTexture), null); AudioManager.StopMusic(); return; } // Cause the ninja and title text to appear gradually ninjaTimer += gameTime.ElapsedGameTime; titleTimer += gameTime.ElapsedGameTime; switch (ninjaState) { case ElementState.Invisible: if (ninjaTimer >= ninjaAppearDelay) { ninjaState = ElementState.Appearing; ninjaTimer = TimeSpan.Zero; } break; case ElementState.Appearing: ninjaOffset = ninjaInitialOffset * (float)Math.Pow(1 - ninjaTimer.TotalMilliseconds / ninjaAppearDuration.TotalMilliseconds, 2); if (ninjaTimer > ninjaAppearDuration) { ninjaState = ElementState.Visible; } break; case ElementState.Visible: // Nothing to do in this state break; default: break; } switch (titleState) { case ElementState.Invisible: if (titleTimer >= titleAppearDelay) { titleState = ElementState.Appearing; titleTimer = TimeSpan.Zero; } break; case ElementState.Appearing: titleOffset = titleInitialOffset * (float)Math.Pow(1 - titleTimer.TotalMilliseconds / titleAppearDuration.TotalMilliseconds, 2); if (titleTimer > titleAppearDuration) { titleState = ElementState.Visible; } break; case ElementState.Visible: // Nothing to do in this state break; default: break; } }