Пример #1
0
        private void SetControllerForPlayer(PlayerIndex player, InputProcessorBase controller)
        {
            int controllerIndex = -1;

            for (int i = 0; i < _controllers.Count; i++)
            {
                if (_controllers[i] == controller)
                {
                    controllerIndex = i; break;
                }
            }

            switch (player)
            {
            case PlayerIndex.One: _playerOneController = controllerIndex; break;

            case PlayerIndex.Two: _playerTwoController = controllerIndex; break;
            }
        }
Пример #2
0
        private void CheckForAndHandleInputFromSingleSource(InputProcessorBase inputSource, int millisecondsSinceLastUpdate)
        {
            if ((inputSource.ProcessorType == InputProcessorBase.InputProcessorType.Keyboard) ||
                (inputSource.ProcessorType == InputProcessorBase.InputProcessorType.Gamepad))
            {
                CheckDirectionalMovementAndUpdateActiveButton(inputSource, millisecondsSinceLastUpdate);
            }

            CheckForAndHandleSelection(inputSource);
        }
Пример #3
0
        private void CheckDirectionalMovementAndUpdateActiveButton(InputProcessorBase inputSource, int millisecondsSinceLastUpdate)
        {
            _millisecondsSinceLastMovement = Math.Min(_millisecondsSinceLastMovement + millisecondsSinceLastUpdate, Movement_Repeat_Time_In_Milliseconds);

            MovementDirection direction = MovementDirection.None;
            if (inputSource.MoveUp) { direction = MovementDirection.Up; }
            else if (inputSource.MoveDown) { direction = MovementDirection.Down; }
            else if (inputSource.MoveLeft) { direction = MovementDirection.Left; }
            else if (inputSource.MoveRight) { direction = MovementDirection.Right; }

            if ((direction == _lastMovementDirection) && (_millisecondsSinceLastMovement < Movement_Repeat_Time_In_Milliseconds))
            {
                direction = MovementDirection.None;
            }

            if (direction != MovementDirection.None)
            {
                switch (direction)
                {
                    case MovementDirection.Up: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingUp); break;
                    case MovementDirection.Down: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingDown); break;
                    case MovementDirection.Left: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingLeft); break;
                    case MovementDirection.Right: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingRight); break;
                }

                _lastMovementDirection = direction;
                _millisecondsSinceLastMovement = 0;
            }
        }
Пример #4
0
 public static void SetPlayerTwoController(InputProcessorBase controller)
 {
     _instance.SetControllerForPlayer(PlayerIndex.Two, controller);
 }