示例#1
0
        protected override void MovementCommandValidation()
        {
            MovementCommandArgs args = new MovementCommandArgs()
            {
                From = InputType.GamePad
            };

            if (currentGamePadState.DPad.Left == ButtonState.Pressed ||
                currentGamePadState.IsButtonDown(Buttons.LeftThumbstickLeft))
            {
                args.HorizontalDirection = HorizontalDirection.Left;
            }
            else if (currentGamePadState.DPad.Right == ButtonState.Pressed ||
                     currentGamePadState.IsButtonDown(Buttons.LeftThumbstickRight))
            {
                args.HorizontalDirection = HorizontalDirection.Right;
            }

            if (currentGamePadState.DPad.Up == ButtonState.Pressed ||
                currentGamePadState.IsButtonDown(Buttons.LeftThumbstickUp))
            {
                args.VerticalDirection = VerticalDirection.Up;
            }
            else if (currentGamePadState.DPad.Down == ButtonState.Pressed ||
                     currentGamePadState.IsButtonDown(Buttons.LeftThumbstickDown))
            {
                args.VerticalDirection = VerticalDirection.Down;
            }

            if (args.HorizontalDirection.HasValue || args.VerticalDirection.HasValue)
            {
                onMovementCommand?.Invoke(this, args);
            }
        }
示例#2
0
        protected override void MovementCommandValidation()
        {
            MovementCommandArgs args = new MovementCommandArgs()
            {
                From = InputType.Keyboard
            };

            if (currentKeyboardState.IsKeyDown(leftKey))
            {
                args.HorizontalDirection = HorizontalDirection.Left;
            }
            else if (currentKeyboardState.IsKeyDown(rightKey))
            {
                args.HorizontalDirection = HorizontalDirection.Right;
            }

            if (currentKeyboardState.IsKeyDown(upKey))
            {
                args.VerticalDirection = VerticalDirection.Up;
            }
            else if (currentKeyboardState.IsKeyDown(downKey))
            {
                args.VerticalDirection = VerticalDirection.Down;
            }

            if (args.HorizontalDirection.HasValue || args.VerticalDirection.HasValue)
            {
                onMovementCommand?.Invoke(this, args);
            }
        }