private void ActivateCommand(ref InputCommand inputCommand)
 {
     if (!inputCommand.isDown)
     {
         inputCommand.pressed = true;
     }
     else
     {
         inputCommand.pressed = false;
     }
     inputCommand.isDown = true;
 }
示例#2
0
        public List <InputCommand> Update()
        {
            KeyboardState keyboard = Keyboard.GetState();
            GamePadState  gamePad  = GamePad.GetState(PlayerIndex.One);

            for (int i = 0; i < this.commands.Count(); i++)
            {
                InputCommand inputCommand = this.commands[i];
                if (keyboard.IsKeyDown(inputCommand.key) || (gamePad.IsButtonDown(inputCommand.button) && !inputCommand.thumbstick) ||
                    this.ThumbsticksMatch(ref inputCommand, gamePad))
                {
                    this.ActivateCommand(ref inputCommand);
                }
                else
                {
                    this.DeactivateCommand(ref inputCommand);
                }
                this.commands[i] = inputCommand;
            }
            return(this.commands);
        }
示例#3
0
        public void AddCommand(string objectName, string methodName, object[] parameters, Keys key, Buttons button)
        {
            InputCommand inputCommand = new InputCommand();
            inputCommand.objectName = objectName;
            inputCommand.methodName = methodName;
            inputCommand.parameters = parameters;
            inputCommand.key = key;
            inputCommand.button = button;
            inputCommand.isDown = false;
            inputCommand.pressed = false;
            inputCommand.magnitude = 0;

            if (button.Equals(Buttons.LeftThumbstickDown) || button.Equals(Buttons.LeftThumbstickUp) || button.Equals(Buttons.LeftThumbstickLeft) || button.Equals(Buttons.LeftThumbstickRight) ||
                button.Equals(Buttons.RightThumbstickDown) || button.Equals(Buttons.RightThumbstickUp) || button.Equals(Buttons.RightThumbstickLeft) || button.Equals(Buttons.RightThumbstickRight))
            {
                inputCommand.thumbstick = true;
            }
            else
            {
                inputCommand.thumbstick = false;
            }
            this.commands.Add(inputCommand);
        }
示例#4
0
        public void AddCommand(string objectName, string methodName, object[] parameters, Keys key, Buttons button)
        {
            InputCommand inputCommand = new InputCommand();

            inputCommand.objectName = objectName;
            inputCommand.methodName = methodName;
            inputCommand.parameters = parameters;
            inputCommand.key        = key;
            inputCommand.button     = button;
            inputCommand.isDown     = false;
            inputCommand.pressed    = false;
            inputCommand.magnitude  = 0;

            if (button.Equals(Buttons.LeftThumbstickDown) || button.Equals(Buttons.LeftThumbstickUp) || button.Equals(Buttons.LeftThumbstickLeft) || button.Equals(Buttons.LeftThumbstickRight) ||
                button.Equals(Buttons.RightThumbstickDown) || button.Equals(Buttons.RightThumbstickUp) || button.Equals(Buttons.RightThumbstickLeft) || button.Equals(Buttons.RightThumbstickRight))
            {
                inputCommand.thumbstick = true;
            }
            else
            {
                inputCommand.thumbstick = false;
            }
            this.commands.Add(inputCommand);
        }
        private bool ThumbsticksMatch(ref InputCommand inputCommand, GamePadState gamePad)
        {
            switch (inputCommand.button)
            {
            case Buttons.LeftThumbstickUp:
            {
                if (gamePad.ThumbSticks.Left.Y > ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.Y) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }

            case Buttons.LeftThumbstickLeft:
            {
                if (gamePad.ThumbSticks.Left.X < -ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.X) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }

            case Buttons.LeftThumbstickDown:
            {
                if (gamePad.ThumbSticks.Left.Y < -ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.Y) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }

            case Buttons.LeftThumbstickRight:
            {
                if (gamePad.ThumbSticks.Left.X > ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.X) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }

            case Buttons.RightThumbstickUp:
            {
                if (gamePad.ThumbSticks.Right.Y > ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.Y) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }

            case Buttons.RightThumbstickLeft:
            {
                if (gamePad.ThumbSticks.Right.X < -ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.X) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }

            case Buttons.RightThumbstickDown:
            {
                if (gamePad.ThumbSticks.Right.Y < -ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.Y) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }

            case Buttons.RightThumbstickRight:
            {
                if (gamePad.ThumbSticks.Right.X > ThumbstickThreshold)
                {
                    inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.X) - ThumbstickThreshold) * 2;
                    return(true);
                }
                break;
            }
            }
            inputCommand.magnitude = 1;
            return(false);
        }
 private void DeactivateCommand(ref InputCommand inputCommand)
 {
     inputCommand.pressed = false;
     inputCommand.isDown  = false;
 }
示例#7
0
 private void ActivateCommand(ref InputCommand inputCommand)
 {
     if (!inputCommand.isDown)
     {
         inputCommand.pressed = true;
     }
     else
     {
         inputCommand.pressed = false;
     }
     inputCommand.isDown = true;
 }
示例#8
0
        private bool ThumbsticksMatch(ref InputCommand inputCommand, GamePadState gamePad)
        {
            switch(inputCommand.button)
            {
                case Buttons.LeftThumbstickUp:
                {
                    if (gamePad.ThumbSticks.Left.Y > ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.Y) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }

                case Buttons.LeftThumbstickLeft:
                {
                    if (gamePad.ThumbSticks.Left.X < -ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.X) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }

                case Buttons.LeftThumbstickDown:
                {
                    if (gamePad.ThumbSticks.Left.Y < -ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.Y) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }

                case Buttons.LeftThumbstickRight:
                {
                    if (gamePad.ThumbSticks.Left.X > ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Left.X) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }
                case Buttons.RightThumbstickUp:
                {
                    if (gamePad.ThumbSticks.Right.Y > ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.Y) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }

                case Buttons.RightThumbstickLeft:
                {
                    if (gamePad.ThumbSticks.Right.X < -ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.X) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }

                case Buttons.RightThumbstickDown:
                {
                    if (gamePad.ThumbSticks.Right.Y < -ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.Y) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }

                case Buttons.RightThumbstickRight:
                {
                    if (gamePad.ThumbSticks.Right.X > ThumbstickThreshold)
                    {
                        inputCommand.magnitude = (Math.Abs(gamePad.ThumbSticks.Right.X) - ThumbstickThreshold) * 2;
                        return true;
                    }
                    break;
                }
            }
            inputCommand.magnitude = 1;
            return false;
        }
示例#9
0
 private void DeactivateCommand(ref InputCommand inputCommand)
 {
     inputCommand.pressed = false;
     inputCommand.isDown = false;
 }