/// <summary> /// Allows the game to run logic. /// </summary> protected override void Update(GameTime gameTime) { healthBar.Update(); lastKeyboardState = currentKeyboardState; lastMousState = currentMouseState; currentKeyboardState = Keyboard.GetState(); // Exit when the Escape key or Back button is pressed if (currentKeyboardState.IsKeyDown(Keys.Escape)) { Exit(); } // Pressing the A button or key toggles the spring behavior on and off if (lastKeyboardState.IsKeyUp(Keys.Space) && (currentKeyboardState.IsKeyDown(Keys.Space))) { cameraSpringEnabled = !cameraSpringEnabled; } // Reset the ship on R key or right thumb stick clicked if (currentKeyboardState.IsKeyDown(Keys.R) || currentGamePadState.Buttons.RightStick == ButtonState.Pressed) { ship.Reset(); camera.Reset(); } // Update the ship ship.Update(gameTime); // Update the camera to chase the new target UpdateCameraChaseTarget(); // The chase camera's update behavior is the springs, but we can // use the Reset method to have a locked, spring-less camera if (cameraSpringEnabled) { camera.Update(gameTime); } else { camera.Reset(); } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic. /// </summary> protected override void Update(GameTime gameTime) { lastKeyboardState = currentKeyboardState; lastGamePadState = currentGamePadState; lastMousState = currentMouseState; #if WINDOWS_PHONE currentKeyboardState = new KeyboardState(); #else currentKeyboardState = Keyboard.GetState(); #endif currentGamePadState = GamePad.GetState(PlayerIndex.One); currentMouseState = Mouse.GetState(); // Exit when the Escape key or Back button is pressed if (currentKeyboardState.IsKeyDown(Keys.Escape) || currentGamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } bool touchTopLeft = currentMouseState.LeftButton == ButtonState.Pressed && lastMousState.LeftButton != ButtonState.Pressed && currentMouseState.X < GraphicsDevice.Viewport.Width / 10 && currentMouseState.Y < GraphicsDevice.Viewport.Height / 10; // Pressing the A button or key toggles the spring behavior on and off if (lastKeyboardState.IsKeyUp(Keys.A) && (currentKeyboardState.IsKeyDown(Keys.A)) || (lastGamePadState.Buttons.A == ButtonState.Released && currentGamePadState.Buttons.A == ButtonState.Pressed) || touchTopLeft) { cameraSpringEnabled = !cameraSpringEnabled; } // Reset the ship on R key or right thumb stick clicked if (currentKeyboardState.IsKeyDown(Keys.R) || currentGamePadState.Buttons.RightStick == ButtonState.Pressed) { ship.Reset(); camera.Reset(); } // Update the ship ship.Update(gameTime); // Update the camera to chase the new target UpdateCameraChaseTarget(); // The chase camera's update behavior is the springs, but we can // use the Reset method to have a locked, spring-less camera if (cameraSpringEnabled) { camera.Update(gameTime); } else { camera.Reset(); } base.Update(gameTime); }