Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
 public static bool IsKeyDown(Keys key) => _currentKeyboardState.IsKeyDown(key);