/// <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) { // escape key missing // Add your update logic here KeyboardState kb = Keyboard.GetState(); if (kb.IsKeyDown(Keys.Back) && !oldKb.IsKeyDown(Keys.Back)) { this.Exit(); } // Methods from the Menus class to run the menus menus.Navigations(gameState, instructionState, kb, CurrentBackgroundC, oldKb, timer, gameOverTimer); gameState = menus.GameStateValue(); instructionState = menus.InstructionStateValue(); if (gameState == GameState.Game) { if (changeSongs == false) { changeSongs = true; MediaPlayer.Stop(); } // Pauses game. Currently does not work if (kb.IsKeyDown(Keys.P) && oldKb != kb) { gameState = GameState.Paused; } // Update Player collision with map obstacles. firstMap.MapPlayerCollisions(p1); firstMap.MapPlayerCollisions(p2); CurrentBackgroundC = firstMap.FLOORCOLOR; p1.update(1, p2); p2.update(2, p1); RoundOverCheck(); } if (gameState == GameState.StartScreen) { p1.Reset(); p2.Reset(); p1.TotalReset(); p2.TotalReset(); CurrentBackgroundC = Color.Black; } if (menus.ReturnTimer() >= 240) { //Reset p1.Reset(); p2.Reset(); while (p1.pRect.Intersects(p2.pRect)) { p2.newRandomStart(); } //CurrentBackgroundC = Color.Black; } // Keep so the player can choose to exit the game if (gameState == GameState.Exit) { this.Exit(); } // Splash screen timer timer++; if ((gameState == GameState.StartScreen || gameState == GameState.Instructions) && (MediaPlayer.State == MediaState.Stopped || changeSongs == true)) { if (changeSongs == true) { changeSongs = false; MediaPlayer.Stop(); } MediaPlayer.Play(songs[0]); } if (gameState == GameState.Game && MediaPlayer.State == MediaState.Stopped) { MediaPlayer.Play(songs[1]); } if (gameState == GameState.RoundOver) { MediaPlayer.Pause(); } else { MediaPlayer.Resume(); } if (gameState == GameState.GameOver) { MediaPlayer.Pause(); changeSongs = true; } oldKb = kb; base.Update(gameTime); }