Exemple #1
0
 private float GetGamePadButtonForce(InputState state)
 {
     var gamePadState = state.GetGamePadState(_gamePadIndex);
     var buttons = gamePadState.Buttons;
     switch (_button)
     {
         case GamePadButtonType.A: return buttons.A == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.B: return buttons.B == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.Back: return buttons.Back == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.BigButton: return buttons.BigButton == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.LShoulder: return buttons.LeftShoulder == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.LStick: return buttons.LeftStick == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.RShoulder: return buttons.RightShoulder == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.RStick: return buttons.RightStick == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.Start: return buttons.Start == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.X: return buttons.X == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.Y: return buttons.Y == ButtonState.Pressed ? 1 : 0;
         case GamePadButtonType.LTrigger: return gamePadState.Triggers.Left;
         case GamePadButtonType.RTrigger: return gamePadState.Triggers.Right;
         default: throw new ApplicationException("Unexpected game pad button " + _button);
     }
 }
Exemple #2
0
 private void UpdateInputState()
 {
     _oldState = _newState;
     _newState = InputState.GetState();
 }
Exemple #3
0
 private bool IsGamePadStickDirectionPressed(InputState state)
 {
     var gamePadState = state.GetGamePadState(_gamePadIndex);
     switch (_stick)
     {
         case GamePadStickType.DPad:
             switch (_direction)
             {
                 case GamePadStickDirectionType.Up: return gamePadState.DPad.Up == ButtonState.Pressed;
                 case GamePadStickDirectionType.Down: return gamePadState.DPad.Down == ButtonState.Pressed;
                 case GamePadStickDirectionType.Left: return gamePadState.DPad.Left == ButtonState.Pressed;
                 case GamePadStickDirectionType.Right: return gamePadState.DPad.Right == ButtonState.Pressed;
                 default: throw new ApplicationException("Unexpected game pad stick direction " + _direction);
             }
         case GamePadStickType.LThumb:
             switch (_direction)
             {
                 case GamePadStickDirectionType.Up: return gamePadState.ThumbSticks.Left.Y > 0.5f;
                 case GamePadStickDirectionType.Down: return gamePadState.ThumbSticks.Left.Y < -0.5f;
                 case GamePadStickDirectionType.Left: return gamePadState.ThumbSticks.Left.X < -0.5f;
                 case GamePadStickDirectionType.Right: return gamePadState.ThumbSticks.Left.X > 0.5f;
                 default: throw new ApplicationException("Unexpected game pad stick direction " + _direction);
             }
         case GamePadStickType.RThumb:
             switch (_direction)
             {
                 case GamePadStickDirectionType.Up: return gamePadState.ThumbSticks.Right.Y > 0.5f;
                 case GamePadStickDirectionType.Down: return gamePadState.ThumbSticks.Right.Y < -0.5f;
                 case GamePadStickDirectionType.Left: return gamePadState.ThumbSticks.Right.X < -0.5f;
                 case GamePadStickDirectionType.Right: return gamePadState.ThumbSticks.Right.X > 0.5f;
                 default: throw new ApplicationException("Unexpected game pad stick direction " + _direction);
             }
         default: throw new ApplicationException("Unexpected game pad stick " + _stick);
     }
 }
Exemple #4
0
 private float GetGamePadStickDirectionForce(InputState state)
 {
     var gamePadState = state.GetGamePadState(_gamePadIndex);
     switch (_stick)
     {
         case GamePadStickType.DPad:
             switch (_direction)
             {
                 case GamePadStickDirectionType.Up: return gamePadState.DPad.Up == ButtonState.Pressed ? 1 : 0;
                 case GamePadStickDirectionType.Down: return gamePadState.DPad.Down == ButtonState.Pressed ? 1 : 0;
                 case GamePadStickDirectionType.Left: return gamePadState.DPad.Left == ButtonState.Pressed ? 1 : 0;
                 case GamePadStickDirectionType.Right: return gamePadState.DPad.Right == ButtonState.Pressed ? 1 : 0;
                 default: throw new ApplicationException("Unexpected game pad stick direction " + _direction);
             }
         case GamePadStickType.LThumb:
             switch (_direction)
             {
                 case GamePadStickDirectionType.Up: return Math.Max(0, gamePadState.ThumbSticks.Left.Y);
                 case GamePadStickDirectionType.Down: return Math.Max(0, -gamePadState.ThumbSticks.Left.Y);
                 case GamePadStickDirectionType.Left: return Math.Max(0, -gamePadState.ThumbSticks.Left.X);
                 case GamePadStickDirectionType.Right: return Math.Max(0, gamePadState.ThumbSticks.Left.X);
                 default: throw new ApplicationException("Unexpected game pad stick direction " + _direction);
             }
         case GamePadStickType.RThumb:
             switch (_direction)
             {
                 case GamePadStickDirectionType.Up: return Math.Max(0, gamePadState.ThumbSticks.Right.Y);
                 case GamePadStickDirectionType.Down: return Math.Max(0, -gamePadState.ThumbSticks.Right.Y);
                 case GamePadStickDirectionType.Left: return Math.Max(0, -gamePadState.ThumbSticks.Right.X);
                 case GamePadStickDirectionType.Right: return Math.Max(0, gamePadState.ThumbSticks.Right.X);
                 default: throw new ApplicationException("Unexpected game pad stick direction " + _direction);
             }
         default: throw new ApplicationException("Unexpected game pad stick " + _stick);
     }
 }