private void ProcessMovement(GameTime gameTime, Moveable moveable, KeyboardStateExtended keyboardState) { var normalizedMotion = Vector2.Zero; if (keyboardState.IsKeyDown(Keys.W)) { normalizedMotion += new Vector2(0, -1); } if (keyboardState.IsKeyDown(Keys.S)) { normalizedMotion += new Vector2(0, 1); } if (keyboardState.IsKeyDown(Keys.A)) { normalizedMotion += new Vector2(-1, 0); } if (keyboardState.IsKeyDown(Keys.D)) { normalizedMotion += new Vector2(1, 0); } moveable.Velocity = normalizedMotion * moveable.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; }
public void MovePaddlePlayer(KeyboardStateExtended keyState, int screenHeight) { if (keyState.IsKeyDown(Keys.Up)) { Position.Y -= Velocity; } else if (keyState.IsKeyDown(Keys.Down)) { Position.Y += Velocity; } if (BoundingRectangle.Top < 0) { Position.Y = BoundingRectangle.Height / 2f; } if (BoundingRectangle.Bottom > screenHeight) { Position.Y = screenHeight - BoundingRectangle.Height / 2f; } }
public static bool IsKeyDown(Keys key) => _currentKeyboardState.IsKeyDown(key);