예제 #1
0
        internal void UpdateState(ref InputState inputState, UpdateState gameState, KeyboardMouseControlMapping mapping, ControlInput inputType, bool windowFocused)
        {
            GamePadState gps;

            switch (inputType)
            {
#if !XBOX360
            case ControlInput.KeyboardMouse:
                this.kms.WindowFocused = windowFocused;
                UpdateState(gameState, inputState, KeyboardMouseState, mapping);
                return;
#endif
            case ControlInput.GamePad1:
                gameState.GetGamePadState(0, out gps);
                UpdateState(gameState, inputState, gps);
                return;

            case ControlInput.GamePad2:
                gameState.GetGamePadState(1, out gps);
                UpdateState(gameState, inputState, gps);
                return;

            case ControlInput.GamePad3:
                gameState.GetGamePadState(2, out gps);
                UpdateState(gameState, inputState, gps);
                return;

            case ControlInput.GamePad4:
                gameState.GetGamePadState(3, out gps);
                UpdateState(gameState, inputState, gps);
                return;
            }
            throw new ArgumentException();
        }
예제 #2
0
        /// <summary>
        /// Override this method to change how raw keyboard and mouse input values are translated to a <see cref="InputState"/> object
        /// </summary>
        /// <param name="gameState"></param>
        /// <param name="state">structure to write input state values</param>
        /// <param name="inputState">stores raw keyboard state</param>
        /// <param name="mapping">stores the current mapped input values</param>
        protected virtual void UpdateState(UpdateState gameState, InputState state, KeyboardMouseState inputState, KeyboardMouseControlMapping mapping)
        {
            long tick = gameState.TotalTimeTicks;

            state.buttons.a.SetState(mapping.A.GetValue(inputState), tick);
            state.buttons.b.SetState(mapping.B.GetValue(inputState), tick);
            state.buttons.x.SetState(mapping.X.GetValue(inputState), tick);
            state.buttons.y.SetState(mapping.Y.GetValue(inputState), tick);

            state.buttons.dpadD.SetState(mapping.DpadDown.GetValue(inputState), tick);
            state.buttons.dpadU.SetState(mapping.DpadUp.GetValue(inputState), tick);
            state.buttons.dpadL.SetState(mapping.DpadLeft.GetValue(inputState), tick);
            state.buttons.dpadR.SetState(mapping.DpadRight.GetValue(inputState), tick);

            state.buttons.shoulderL.SetState(mapping.LeftShoulder.GetValue(inputState), tick);
            state.buttons.shoulderR.SetState(mapping.RightShoulder.GetValue(inputState), tick);

            state.buttons.back.SetState(mapping.Back.GetValue(inputState), tick);
            state.buttons.start.SetState(mapping.Start.GetValue(inputState), tick);
            state.buttons.leftStickClick.SetState(mapping.LeftStickClick.GetValue(inputState), tick);
            state.buttons.rightStickClick.SetState(mapping.RightStickClick.GetValue(inputState), tick);

            state.triggers.leftTrigger  = mapping.LeftTrigger.GetValue(inputState, false);
            state.triggers.rightTrigger = mapping.RightTrigger.GetValue(inputState, false);

            Vector2 v = new Vector2();

            v.Y = mapping.LeftStickForward.GetValue(inputState, false) + mapping.LeftStickBackward.GetValue(inputState, true);
            v.X = mapping.LeftStickLeft.GetValue(inputState, true) + mapping.LeftStickRight.GetValue(inputState, false);

            state.sticks.leftStick = v;

            v.Y = mapping.RightStickForward.GetValue(inputState, false) + mapping.RightStickBackward.GetValue(inputState, true);
            v.X = mapping.RightStickLeft.GetValue(inputState, true) + mapping.RightStickRight.GetValue(inputState, false);

            state.sticks.rightStick = v;
        }