/// <summary> /// Update the entity. This is usually performed in the gameloop /// </summary> /// <param name="inputManager"></param> /// <param name="gameTime"></param> public override void Update(InputManager inputManager, GameTime gameTime) { /// Handle controls var keyboard = inputManager.CurrentKeyboardState; var gamepad = inputManager.CurrentGamePadState; if (TitlescreenStatus == Entities.TitlescreenStatus.Start) { if (keyboard.IsKeyDown(Keys.F1) || gamepad.Buttons.Y == ButtonState.Pressed) { if (gamepad.Buttons.Y == ButtonState.Pressed) { isGamepad = true; } TitlescreenStatus = TitlescreenStatus.Help; } else if (keyboard.IsKeyDown(Keys.Space) || keyboard.IsKeyDown(Keys.Enter) || gamepad.Buttons.A == ButtonState.Pressed) { if (Player.Alive) { /// Resume game Visible = false; } else { /// Start new game Visible = false; NewGameRequested = true; } } else if (inputManager.WasKeyPressed(Keys.Escape) || inputManager.WasButtonPressed(Buttons.Back)) { ExitRequested = true; } } else { if (inputManager.WasKeyPressed(Keys.Escape) || inputManager.WasButtonPressed(Buttons.Back)) { TitlescreenStatus = TitlescreenStatus.Start; } } base.Update(inputManager, gameTime); }
/// <summary> /// Update. This is where we handle the controls. /// </summary> /// <param name="inputManager"></param> /// <param name="gameTime"></param> public override void Update(InputManager inputManager, GameTime gameTime) { this.gameTime = gameTime; /// Handle controls var keyboard = inputManager.CurrentKeyboardState; var gamepad = inputManager.CurrentGamePadState; /// If the user is pressing left on the DPad or keyboard if (keyboard.IsKeyDown(Keys.Left) || gamepad.DPad.Left == ButtonState.Pressed) { Rotate(-RotationSpeed); } /// If the user is pressing right on the DPad or keyboard else if (keyboard.IsKeyDown(Keys.Right) || gamepad.DPad.Right == ButtonState.Pressed) { Rotate(RotationSpeed); } /// If the user is pressing up on the DPad or keyboard if (keyboard.IsKeyDown(Keys.Up) || gamepad.DPad.Up == ButtonState.Pressed) { Forward(); } else { /// Handle Deccelerate... CurrentSpeed = new Vector2(CurrentSpeed.X / 1.05f, CurrentSpeed.Y / 1.05f); } base.Update(inputManager, gameTime); /// Handle Hyperspace. The condition is that the user can't hold /// down a hyperspace. if (inputManager.WasKeyPressed(Keys.H) || inputManager.WasButtonPressed(Buttons.B) && (gameTime.TotalGameTime.TotalSeconds - lastHyperspaceTime) > hyperspaceTime) { var random = new Random(); float x = random.Next(GraphicsDevice.Viewport.X, GraphicsDevice.Viewport.Width); float y = random.Next(GraphicsDevice.Viewport.Y, GraphicsDevice.Viewport.Height); Position = new Vector2(x, y); lastHyperspaceTime = gameTime.TotalGameTime.TotalSeconds; } /// Fire bullet if (keyboard.IsKeyDown(Keys.Space) || gamepad.Buttons.A == ButtonState.Pressed) { FireBullet(new Vector2(5.0f, 5.0f)); } }