/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // TODO: Add your update logic here if (input.KeyJustPressed(Keys.F11)) graphics.ToggleFullScreen(); if (PlayerIndexChosen && !GamePad.GetState((PlayerIndex)selectedIndex).IsConnected) { PlayerIndexChosen = false; } if (!PlayerIndexChosen) { for (int i = (int)PlayerIndex.One; i < (int)PlayerIndex.Four; i++) { if (GamePad.GetState((PlayerIndex)i).Buttons.A == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.B == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.Back == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.BigButton == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.LeftShoulder == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.LeftStick == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.RightShoulder == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.RightStick == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.Start == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.X == ButtonState.Pressed || GamePad.GetState((PlayerIndex)i).Buttons.Y == ButtonState.Pressed) { selectedIndex = (PlayerIndex)i; PlayerIndexChosen = true; break; } } } switch (currentGameState) { case GameState.MainMenu: if (input.KeyJustPressed(Keys.Escape) || ButtonJustPressed(Buttons.Back)) this.Exit(); if(!mainMenuSongStart) { try { gameSongStart = false; creditsSongStart = false; mainMenuCue = soundBank.GetCue("KnowThyself"); mainMenuCue.Play(); mainMenuSongStart = true; } catch (InvalidOperationException e) { } } ManageMainMenu(); break; case GameState.Instructions: if (input.KeyJustPressed(Keys.Escape) || instructionsScreen.IsMouseSelectedAndClicked || PressedAnything()) { sfx_menuSelection.Play(); if (isPaused) { currentGameState = GameState.InGame; instructionsScreen.ResetPosition(); } else { currentGameState = GameState.MainMenu; instructionsScreen.ResetPosition(); } } instructionsScreen.Update(gameTime); break; case GameState.Credits: if (input.KeyJustPressed(Keys.Escape) || creditsScreen.IsMouseSelectedAndClicked || PressedAnything()) { sfx_menuSelection.Play(); currentGameState = GameState.MainMenu; creditsScreen.ResetPosition(); creditsCue.Stop(AudioStopOptions.Immediate); creditsCue = soundBank.GetCue("Credits"); } creditsScreen.Update(gameTime); if (!creditsSongStart) { mainMenuSongStart = false; gameSongStart = false; creditsCue.Play(); creditsSongStart = true; } break; case GameState.InGame: UpdateGame(gameTime); if (level != null && level.GameEnded != 0) { MediaPlayer.Stop(); byte endGame = level.GameEnded; level.Dispose(); level = null; if (endGame == 1) { sfx_gameWin.Play(); currentGameState = GameState.GameClear; } else if (endGame == 2) { sfx_endGame.Play(); currentGameState = GameState.GameOver; } } if (!gameSongStart) { mainMenuSongStart = false; creditsSongStart = false; inGameCue = soundBank.GetCue("InGameMusic"); inGameCue.Play(); gameSongStart = true; } break; case GameState.GameClear: if (input.KeyJustPressed(Keys.Escape) || gameCompleteScreen.IsMouseSelectedAndClicked2 || PressedAnything()) { sfx_menuSelection.Play(); currentGameState = GameState.MainMenu; gameCompleteScreen = new NotificationScroll(Content, input, "UI/dialog-backdrop", "You Have Won!"); } else if (gameCompleteScreen.IsMouseSelectedAndClicked1) { sfx_menuSelection.Play(); level = new Level(Services, graphics); currentGameState = GameState.InGame; gameCompleteScreen = new NotificationScroll(Content, input, "UI/dialog-backdrop", "You Have Won!"); } gameCompleteScreen.Update(gameTime); break; case GameState.GameOver: if (input.KeyJustPressed(Keys.Escape) || gameOverScreen.IsMouseSelectedAndClicked2 || PressedAnything()) { sfx_menuSelection.Play(); currentGameState = GameState.MainMenu; gameOverScreen = new NotificationScroll(Content, input, "UI/dialog-backdrop", "Game Over"); } else if (gameOverScreen.IsMouseSelectedAndClicked1) { sfx_menuSelection.Play(); level = new Level(Services, graphics); currentGameState = GameState.InGame; gameOverScreen = new NotificationScroll(Content, input, "UI/dialog-backdrop", "Game Over"); } gameOverScreen.Update(gameTime); break; case GameState.Introduction: if (input.KeyJustPressed(Keys.Escape) || input.KeyJustPressed(Keys.Space) || input.ButtonJustPressed(UserInput.MouseButton.Left) || PressedAnything()) { logoPosition = new Vector2(95, 39); introTime = -1; } if (introTime <= 0) currentGameState = GameState.MainMenu; else { introTime -= gameTime.ElapsedGameTime.TotalSeconds; //System.Diagnostics.Debug.WriteLine("Current Time Remaining: " + introTime); //Increase visibility of buttons. fadeTimer -= gameTime.ElapsedGameTime.TotalSeconds; if (fadeTimer < 0) { alphaValue += fadeIncrement; } //Scroll up sky background if (skyPosition.Y >= 0) skyPosition -= new Vector2(0, 10); //Move ground position. if (groundPosition.Y >= -768) groundPosition -= new Vector2(0, 5); if(groundPosition.Y < 300) groundPosition -= new Vector2(0, 1); //Move mountains. if (mountainsPosition.Y >= -768) mountainsPosition -= new Vector2(0, 5); //Sea position. if (seaPosition.Y >= -768) seaPosition -= new Vector2(0, 5); //Move volcano. if (volcanoPosition.Y >= -768) volcanoPosition -= new Vector2(0, 5); //Move forest into position. if (forest1Position.Y < 768) forest1Position += new Vector2(0, 5); if (forest2Position.Y < 768) forest2Position += new Vector2(0, 5); if (forest3Position.Y < 768) forest3Position += new Vector2(0, 5); if (forest4Position.Y < 768) forest4Position += new Vector2(0, 5); //Move clouds into position. if (cloud1Position.Y < 768) cloud1Position += new Vector2(0, 4); if (cloud2Position.Y < 768) cloud2Position += new Vector2(0, 4); if (cloud3Position.Y < 768) cloud3Position += new Vector2(0, 4); if (cloud4Position.Y < 768) cloud4Position += new Vector2(0, 4); //Logo position. if (logoPosition.Y < 39) logoPosition += new Vector2(0, 1); else logoPosition = new Vector2(95, 39); } if (!mainMenuSongStart) { try { gameSongStart = false; creditsSongStart = false; mainMenuCue.Play(); mainMenuSongStart = true; } catch (InvalidOperationException e) { } } break; } input.Update(gameTime); base.Update(gameTime); prevGamePadState = GamePad.GetState(selectedIndex); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Songs mainMenuSong = Content.Load<Song>("Sound/Know Thyself"); gameSong = Content.Load<Song>("Sound/MainGameMusic"); creditsSong = Content.Load<Song>("Sound/Credits"); MediaPlayer.IsRepeating = true; audioEngine = new AudioEngine("Content/Sound/GameAudio.xgs"); waveBank = new WaveBank(audioEngine, "Content/Sound/Wave Bank.xwb"); soundBank = new SoundBank(audioEngine, "Content/Sound/Sound Bank.xsb"); mainMenuCue = soundBank.GetCue("KnowThyself"); inGameCue = soundBank.GetCue("InGameMusic"); creditsCue = soundBank.GetCue("Credits"); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Fonts lithosProBlack = Content.Load<SpriteFont>("UI/Lithos Pro Regular"); lithosProMenu = Content.Load<SpriteFont>("UI/Lithos Pro Regular Menu"); bradleyHand = Content.Load<SpriteFont>("UI/Bradley Hand ITC TT"); // Load Menu information. pauseOverlay = Content.Load<Texture2D>("Menus/pauseMenuOverlay"); pauseBanner = Content.Load<Texture2D>("UI/paused-banner"); mainMenuBackground = Content.Load<Texture2D>("Menus/backdrop-no-animation"); instructionsScreen = new TextScroll(Content, input, "UI/dialog-instructions"); creditsScreen = new TextScroll(Content, input, "UI/dialog-credits"); gameOverScreen = new NotificationScroll(Content, input, "UI/dialog-backdrop", "Game Over"); gameCompleteScreen = new NotificationScroll(Content, input, "UI/dialog-backdrop", "You Have Won!"); mainMenuIconDimL = Content.Load<Texture2D>("UI/button-dim-left"); mainMenuIconDimR = Content.Load<Texture2D>("UI/button-dim-right"); mainMenuIconDimC = Content.Load<Texture2D>("UI/button-dim-middle"); mainMenuIconLitL = Content.Load<Texture2D>("UI/button-lit-left"); mainMenuIconLitR = Content.Load<Texture2D>("UI/button-lit-right"); mainMenuIconLitC = Content.Load<Texture2D>("UI/button-lit-middle"); pauseMenuIconDimL = Content.Load<Texture2D>("UI/button-dim-left"); pauseMenuIconDimR = Content.Load<Texture2D>("UI/button-dim-right"); pauseMenuIconDimC = Content.Load<Texture2D>("UI/button-dim-middle"); pauseMenuIconLitL = Content.Load<Texture2D>("UI/button-lit-left"); pauseMenuIconLitR = Content.Load<Texture2D>("UI/button-lit-right"); pauseMenuIconLitC = Content.Load<Texture2D>("UI/button-lit-middle"); // UI buttons pauseButtonDim = Content.Load<Texture2D>("UI/pause-dim"); pauseButtonLit = Content.Load<Texture2D>("UI/pause-lit"); UIButton pause = new UIButton(new Vector2(950, 700), this.Content, UIButton.Button.pauseButton, true, -1); pause.OnClick += Pause_OnClick; buttons.Add(pause); int initialX = (graphics.GraphicsDevice.Viewport.Width / 2) - ((mainMenuIconDimL.Width + mainMenuIconDimR.Width + centerIconWidth)/ 2); int initialY = (graphics.GraphicsDevice.Viewport.Height / 4) + 75; // Set up Main Menu. mainMenuItems[0] = new MenuSelection("Play", pauseMenuIconDimL, pauseMenuIconDimR, pauseMenuIconDimC, pauseMenuIconLitL, pauseMenuIconLitR, pauseMenuIconLitC, initialX, initialY, centerIconWidth, lithosProMenu); mainMenuItems[1] = new MenuSelection("Instructions", pauseMenuIconDimL, pauseMenuIconDimR, pauseMenuIconDimC, pauseMenuIconLitL, pauseMenuIconLitR, pauseMenuIconLitC, initialX, initialY + 90, centerIconWidth, lithosProMenu); mainMenuItems[2] = new MenuSelection("Credits", pauseMenuIconDimL, pauseMenuIconDimR, pauseMenuIconDimC, pauseMenuIconLitL, pauseMenuIconLitR, pauseMenuIconLitC, initialX, initialY + 180, centerIconWidth, lithosProMenu); mainMenuItems[3] = new MenuSelection("Exit", pauseMenuIconDimL, pauseMenuIconDimR, pauseMenuIconDimC, pauseMenuIconLitL, pauseMenuIconLitR, pauseMenuIconLitC, initialX, initialY + 270, centerIconWidth, lithosProMenu); // Set up Pause Menu. initialY = (graphics.GraphicsDevice.Viewport.Height / 4) + 25; pauseMenuItems[0] = new MenuSelection("Resume Game", mainMenuIconDimL, mainMenuIconDimR, mainMenuIconDimC, mainMenuIconLitL, mainMenuIconLitR, mainMenuIconLitC, initialX, initialY, centerIconWidth, lithosProMenu); pauseMenuItems[1] = new MenuSelection("Help", mainMenuIconDimL, mainMenuIconDimR, mainMenuIconDimC, mainMenuIconLitL, mainMenuIconLitR, mainMenuIconLitC, initialX, initialY + 90, centerIconWidth, lithosProMenu); pauseMenuItems[2] = new MenuSelection("Return to Title", mainMenuIconDimL, mainMenuIconDimR, mainMenuIconDimC, mainMenuIconLitL, mainMenuIconLitR, mainMenuIconLitC, initialX, initialY + 180, centerIconWidth, lithosProMenu); pauseMenuItems[3] = new MenuSelection("Exit", mainMenuIconDimL, mainMenuIconDimR, mainMenuIconDimC, mainMenuIconLitL, mainMenuIconLitR, mainMenuIconLitC, initialX, initialY + 270, centerIconWidth, lithosProMenu); // Misc advancedHelpIndicator0 = Content.Load<Texture2D>("UI/LvL2_PopUp"); advancedHelpIndicator1 = Content.Load<Texture2D>("UI/Help"); advancedHelpIndicator2 = Content.Load<Texture2D>("UI/Tutorial3"); // SFX sfx_menuSelection = Content.Load<SoundEffect>("SFX/menu selection"); sfx_gameWin = Content.Load<SoundEffect>("SFX/Game Win"); sfx_endGame = Content.Load<SoundEffect>("SFX/End Game"); //Introduction Sequence. finalIntroFrame = Content.Load<Texture2D>("IntroSequence/intro-final-frame"); cloud1 = Content.Load<Texture2D>("IntroSequence/title-cloud1"); cloud2 = Content.Load<Texture2D>("IntroSequence/title-cloud2"); cloud3 = Content.Load<Texture2D>("IntroSequence/title-cloud3"); cloud4 = Content.Load<Texture2D>("IntroSequence/title-cloud4"); forest1 = Content.Load<Texture2D>("IntroSequence/title-forest1"); forest2 = Content.Load<Texture2D>("IntroSequence/title-forest2"); forest3 = Content.Load<Texture2D>("IntroSequence/title-forest3"); forest4 = Content.Load<Texture2D>("IntroSequence/title-forest4"); ground = Content.Load<Texture2D>("IntroSequence/title-ground"); logo = Content.Load<Texture2D>("IntroSequence/title-logo"); mountains = Content.Load<Texture2D>("IntroSequence/title-mountains"); sea = Content.Load<Texture2D>("IntroSequence/title-sea"); sky = Content.Load<Texture2D>("IntroSequence/title-sky"); volcano = Content.Load<Texture2D>("IntroSequence/title-volcano"); }