Exemple #1
0
 DirectionalState(Vector2 direction, Vector2 movement, TimedButtonState up, TimedButtonState down, TimedButtonState left, TimedButtonState right)
 {
     Direction = direction;
     Movement  = movement;
     Up        = up;
     Down      = down;
     Left      = left;
     Right     = right;
 }
Exemple #2
0
 DirectionalState(Vector2 direction, Vector2 movement, TimedButtonState up, TimedButtonState down, TimedButtonState left, TimedButtonState right)
 {
     Direction = direction;
     Movement = movement;
     Up = up;
     Down = down;
     Left = left;
     Right = right;
 }
Exemple #3
0
 ThumbstickState(Vector2 position, Vector2 movement, TimedButtonState clicked, TimedButtonState up, TimedButtonState down, TimedButtonState left, TimedButtonState right)
 {
     Position = position;
     Movement = movement;
     Clicked  = clicked;
     Up       = up;
     Down     = down;
     Left     = left;
     Right    = right;
 }
Exemple #4
0
 ThumbstickState(Vector2 position, Vector2 movement, TimedButtonState clicked, TimedButtonState up, TimedButtonState down, TimedButtonState left, TimedButtonState right)
 {
     Position = position;
     Movement = movement;
     Clicked = clicked;
     Up = up;
     Down = down;
     Left = left;
     Right = right;
 }
Exemple #5
0
        public void Update(TimeSpan elapsed)
        {
            if (!Connected) return;

            State state = Controller.GetState();
            var gamepadState = state.Gamepad;

            // Sadly we can't really use the packet information because everything is temporal
            // Even if everything stayed the same, that's valid data (elapsed time goes up, etc.)

            // Vibration
            if (leftMotor.Active)   leftMotor = UpdateMotor(leftMotor, elapsed);
            if (rightMotor.Active)  rightMotor = UpdateMotor(rightMotor, elapsed);

            if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount)
                Controller.SetVibration(new Vibration
                {
                    LeftMotorSpeed = (ushort) (leftMotor.CurrentAmount * ushort.MaxValue),
                    RightMotorSpeed = (ushort) (rightMotor.CurrentAmount * ushort.MaxValue)
                });

            // Shoulders
            LeftShoulder = LeftShoulder.NextState((gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0, elapsed);
            RightShoulder = RightShoulder.NextState((gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0, elapsed);

            // Triggers
            LeftTrigger = LeftTrigger.NextState(gamepadState.LeftTrigger / (float)byte.MaxValue, elapsed);
            RightTrigger = RightTrigger.NextState(gamepadState.RightTrigger / (float)byte.MaxValue, elapsed);

            // Buttons
            Start = Start.NextState((gamepadState.Buttons & GamepadButtonFlags.Start) != 0);
            Back = Back.NextState((gamepadState.Buttons & GamepadButtonFlags.Back) != 0);

            A = A.NextState((gamepadState.Buttons & GamepadButtonFlags.A) != 0, elapsed);
            B = B.NextState((gamepadState.Buttons & GamepadButtonFlags.B) != 0, elapsed);
            X = X.NextState((gamepadState.Buttons & GamepadButtonFlags.X) != 0, elapsed);
            Y = Y.NextState((gamepadState.Buttons & GamepadButtonFlags.Y) != 0, elapsed);

            // D-Pad
            DPad = DPad.NextState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0,
                                  (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0,
                                  (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0,
                                  (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0, elapsed);

            // Thumb sticks
            LeftStick = LeftStick.NextState(
                    Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone),
                    (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0, elapsed);
            RightStick = RightStick.NextState(
                    Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone),
                    (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0, elapsed);
        }