/// <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) { #if PROFILE elapsedTime += gameTime.ElapsedGameTime; if (elapsedTime > TimeSpan.FromMilliseconds(1)) { elapsedTime -= TimeSpan.FromSeconds(1); frameRate = frameCounter; frameCounter = 0; } if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed) { Thread.Sleep(5); } if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed) { return; } #endif #if WINDOWS #if DEBUG // Allows the game to exit; win32 only if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } #endif #endif if (exitGame) { this.Exit(); } if (!(preloadedAssets && preloadedJSon)) { InputDevice2.Update(gameTime); if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.RightDirection) != InputDevice2.PlayerPad.NoPad) { shipRotation += 0.02f; } else if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.LeftDirection) != InputDevice2.PlayerPad.NoPad) { shipRotation -= 0.02f; } if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm) != InputDevice2.PlayerPad.NoPad) { shipVelocity += new Vector2((float)(Math.Cos(shipRotation)), (float)(Math.Sin(shipRotation))) * shipThrust; shipVelocity = Vector2.Clamp(shipVelocity, new Vector2(-0.91f), new Vector2(0.91f)); } shipPosition += shipVelocity * gameTime.ElapsedGameTime.Milliseconds; shipVelocity *= 0.99f; if (shipPosition.X < -1850) { shipPosition.X = 1850; } if (shipPosition.X > 1850) { shipPosition.X = -1850; } if (shipPosition.Y < -1300) { shipPosition.Y = 1300; } if (shipPosition.Y > 1300) { shipPosition.Y = -1300; } return; } gameIsRunningSlowly = gameTime.IsRunningSlowly; if (currentGameScreen.IsComplete) { currentGameScreen = ScreenState.SwitchToNewScreen(currentGameScreen.nextLevelState()); } InputDevice2.Update(gameTime); currentGameScreen.update(gameTime); base.Update(gameTime); }