예제 #1
0
        override protected bool IsPressed()
        {
            GamePadInput pad = GamePadInput.GetGamePad(this.playerIndex);

            return(pad.DPadRight.ButtonState == ButtonState.Pressed &&
                   pad.DPadUp.ButtonState == ButtonState.Released &&
                   pad.DPadDown.ButtonState == ButtonState.Released);
        }
예제 #2
0
 /// <summary>
 /// Is the key currently being pressed down
 /// </summary>
 public bool this[Keys key]
 {
     get
     {
         bool pressed = false;
         if (GamePadInput.GetGamePad(this.playerIndex).IsConnected)
         {
             pressed = (chatpadStates[(int)this.playerIndex][key] == KeyState.Down);
         }
         return(pressed);
     }
 }
예제 #3
0
 override public void Update()
 {
     if (GamePadInput.GetGamePad(this.playerIndex).IsConnected)
     {
         Pressed = chatpadStates[(int)this.playerIndex].IsKeyDown(this.key);
         if (timerAutoRepeat.Running)
         {
             timerAutoRepeat.Update();
         }
     }
     else
     {
         Reset();
     }
 }
예제 #4
0
        override public void Update()
        {
            if (GamePadInput.GetGamePad(this.playerIndex).IsConnected)
            {
                Position = StickValue();

                if (timerAutoRepeat.Running)
                {
                    timerAutoRepeat.Update();
                }
            }
            else
            {
                Reset();
            }
        }
예제 #5
0
        override public void Update()
        {
            if (GamePadInput.GetGamePad(this.playerIndex).IsConnected)
            {
                // specifically call property
                this.Pressed = IsPressed();

                if (timerAutoRepeat.Running)
                {
                    timerAutoRepeat.Update();
                }
            }
            else
            {
                Reset();
            }
        }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            GamePadSensor.PlayerId playerIdSensor = (GamePadSensor.PlayerId)reflex.targetSet.Param;
            if (this.playerId != playerIdSensor)
            {
                this.playerId = playerIdSensor;
                UpdateCommands();
            }

            bool isPitch = (reflex.Selector is MoveDownSelector) ||
                           (reflex.Selector is MoveUpDownSelector) ||
                           (reflex.Selector is MoveUpSelector);
            bool isYaw = !isPitch && reflex.Data.IsMovement();

            bool match = false;

            param = null;
            if (this.stickCommands.Count != 0)
            {
                this.stickPosition = Vector2.Zero;
                for (int indexCommand = 0; indexCommand < this.stickCommands.Count; indexCommand++)
                {
                    StickCommand command = this.stickCommands[indexCommand] as StickCommand;
                    command.Update();
                    // Bias stick input toward center if pushing forward.
                    Vector2 stick = command.Position;

                    if (isPitch)
                    {
                        bool invert = GamePadInput.InvertYAxis(command.playerIndex);
                        if (invert)
                        {
                            stick.Y = -stick.Y;
                        }
                    }
                    if (isYaw)
                    {
                        bool invert = GamePadInput.InvertXAxis(command.playerIndex);
                        if (invert)
                        {
                            stick.X = -stick.X;
                        }
                    }

                    // 5% flat deadzone.
                    Vector2 s;
                    s.X            = stick.X > 0 ? Math.Max(stick.X * 1.05f - 0.05f, 0) : Math.Min(stick.X * 1.05f + 0.05f, 0);
                    s.Y            = stick.Y > 0 ? Math.Max(stick.Y * 1.05f - 0.05f, 0) : Math.Min(stick.Y * 1.05f + 0.05f, 0);
                    stickPosition += s;

                    // If a stick is being used for input in a bot program, don't blend it into gamepad0.
                    if (command is Input.GamePadRightThumbStick)
                    {
                        GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(command.playerIndex)).RightStickIgnoreForGamePad0();
                    }
                    else if (command is Input.GamePadLeftThumbStick)
                    {
                        GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(command.playerIndex)).LeftStickIgnoreForGamePad0();
                    }
                }

                param = this.stickPosition;
                match = (this.stickPosition != Vector2.Zero); // only if not centered
            }

            return(match);
        }
        protected void UpdateCommands()
        {
            this.stickCommands.Clear();

            // Note that we're getting the pads via logical mapping.
            GamePadInput pad1 = GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(PlayerIndex.One));
            GamePadInput pad2 = GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(PlayerIndex.Two));
            GamePadInput pad3 = GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(PlayerIndex.Three));
            GamePadInput pad4 = GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(PlayerIndex.Four));

            switch (this.stick)
            {
            case GamePadStick.Left:
                if (this.playerId == GamePadSensor.PlayerId.All)
                {
                    //add pad 1 if it was touched, we're using virtual controller, or the other pads aren't present
                    if (pad1.EverTouched || InGame.ShowVirtualController || (!pad2.EverTouched && !pad3.EverTouched && !pad4.EverTouched))
                    {
                        this.stickCommands.Add(new GamePadLeftThumbStick(PlayerIndex.One));
                    }
                    if (pad2.EverTouched)
                    {
                        this.stickCommands.Add(new GamePadLeftThumbStick(PlayerIndex.Two));
                    }
                    if (pad3.EverTouched)
                    {
                        this.stickCommands.Add(new GamePadLeftThumbStick(PlayerIndex.Three));
                    }
                    if (pad4.EverTouched)
                    {
                        this.stickCommands.Add(new GamePadLeftThumbStick(PlayerIndex.Four));
                    }
                }
                else
                {
                    this.stickCommands.Add(new GamePadLeftThumbStick((PlayerIndex)this.playerId));
                }
                break;

            case GamePadStick.Right:
                if (this.playerId == GamePadSensor.PlayerId.All)
                {
                    //add pad 1 if it was touched, we're using virtual controller, or the other pads aren't present
                    if (pad1.EverTouched || InGame.ShowVirtualController || (!pad2.EverTouched && !pad3.EverTouched && !pad4.EverTouched))
                    {
                        this.stickCommands.Add(new GamePadRightThumbStick(PlayerIndex.One));
                    }
                    if (pad2.EverTouched)
                    {
                        this.stickCommands.Add(new GamePadRightThumbStick(PlayerIndex.Two));
                    }
                    if (pad3.EverTouched)
                    {
                        this.stickCommands.Add(new GamePadRightThumbStick(PlayerIndex.Three));
                    }
                    if (pad4.EverTouched)
                    {
                        this.stickCommands.Add(new GamePadRightThumbStick(PlayerIndex.Four));
                    }
                }
                else
                {
                    this.stickCommands.Add(new GamePadRightThumbStick((PlayerIndex)this.playerId));
                }
                break;
            }
        }
예제 #8
0
 override protected Vector2 StickValue()
 {
     return(GamePadInput.GetGamePad(this.playerIndex).RightStick);
 }
예제 #9
0
        override public void Update()
        {
            if (GamePadInput.GetGamePad(this.playerIndex).IsConnected)
            {
                bool keyIsPressed = false;

                Keys[] currentPressedKeys = chatpadStates[(int)this.playerIndex].GetPressedKeys();

                // walk both sets of keys; the prev and current
                // which are in order and
                // trigger repeat, press, and release events
                int indexPrev = 0;
                int indexCurr = 0;

                Keys keyPrev;
                Keys keyCurr;

                // while either set still has keys
                while (indexPrev < this.pressedKeys.Length || indexCurr < currentPressedKeys.Length)
                {
                    if (indexPrev < this.pressedKeys.Length)
                    {
                        keyPrev = this.pressedKeys[indexPrev];
                    }
                    else
                    {
                        keyPrev = (Keys)255;// not valid, reached end of this set
                    }
                    if (indexCurr < currentPressedKeys.Length)
                    {
                        keyCurr = currentPressedKeys[indexCurr];
                    }
                    else
                    {
                        keyCurr = (Keys)255; // not valid, reached end of this set
                    }

                    if (keyPrev == keyCurr)
                    {
                        indexPrev++;
                        indexCurr++;
                        // key still pressed
                        if (!IsModifierKey(keyCurr))
                        {
                            keyIsPressed = true;
                        }
                    }
                    else if (keyPrev < keyCurr)
                    {
                        indexPrev++;
                        // key was released
                        if (ReleasePress != null)
                        {
                            ReleasePress(this, new KeyboardKeyEventArgs(keyPrev));
                        }
                    }
                    else
                    {
                        indexCurr++;
                        // new key pressed
                        if (Press != null)
                        {
                            Press(this, new KeyboardKeyEventArgs(keyCurr));
                        }
                        if (CharInput != null)
                        {
                            OnChar(keyCurr);
                        }
                        if (!IsModifierKey(keyCurr))
                        {
                            keyIsPressed = true;
                        }
                    }
                }

                // update generalized state
                if (keyIsPressed)
                {
                    if (state == KeyCommandState.ReleasePress)
                    {
                        // NOTE: do not call Start on this timer, it is being used in a caller update model
                        timerAutoRepeat.Reset(timeFirstAutoRepeat);
                        state = KeyCommandState.Press;
                    }
                }
                else
                {
                    if (state != KeyCommandState.ReleasePress)
                    {
                        timerAutoRepeat.Clear();
                        state = KeyCommandState.ReleasePress;
                    }
                }

                this.pressedKeys = currentPressedKeys;

                if (timerAutoRepeat.Running)
                {
                    timerAutoRepeat.Update();
                }
            }
            else
            {
                Reset();
            }
        }
예제 #10
0
 override protected bool IsPressed()
 {
     return(GamePadInput.GetGamePad(this.playerIndex).ButtonA.ButtonState == ButtonState.Pressed);
 }
예제 #11
0
 protected override bool IsPressed()
 {
     return(GamePadInput.GetGamePad(this.playerIndex).RightTriggerButton.ButtonState == ButtonState.Pressed);
 }
예제 #12
0
 protected override float TriggerValue()
 {
     return(GamePadInput.GetGamePad(this.playerIndex).RightTrigger);
 }