Exemplo n.º 1
0
        public void Send(Gamepad.GamepadOutput player)
        {
            if (!_isConnected)
            {
                if (_class.MDefine.GcmapiConnect != null) _class.MDefine.GcmapiConnect((ushort) _class.Write.DevId);
                _isConnected = true;
            }

            if (_class.MDefine.GcmapiIsConnected(player.Index - 1) == 1)
            {
                //todo: assign active divice to each player. For now, just assign player number to device, also menu options for multiplayer
                _class.MDefine.GcmapiWrite(player.Index - 1, player.Output);
                //_class.MDefine.GcmapiWrite(_activeIndex, player.Output);

                if (!_class.System.UseRumble) return;

                var report = new Define.GcmapiReport();

                if (_class.MDefine.GcmapiRead(player.Index - 1, ref report) != IntPtr.Zero)
                {
                    GamePad.SetState(player.PlayerIndex, report.Rumble[0], report.Rumble[1]);
                }
            }
            else
            {
                _class.System.Debug("titanone.log", "not connected to " + _activeDevice);
            }
        }
 public void Initializegames(Transform[] games, bool[] AIStatus, Gamepad[] newGamepad)
 {
     numOfGames = games.Length;
     Transform input = Instantiate(InputControllerPrefab);
     inputController = input.GetComponent<ScaleableInputController>();
     inputController.gameController = this;
     game = new GameClass[games.Length];
     Rect[] campos = GetCameraPositions(games.Length);
     for (int i = 0; i < games.Length; i++)
     {
         game[i] = MakeGame(games[i], gamePos[i], campos[i], i, offsets[i], AIStatus[i]);
     }
     Camera[] camCol = new Camera[game.Length];
     for (int i = 0; i < games.Length; i++)
     {
         camCol[i] = game[i].cam;
     }
     for (int i = 0; i < games.Length; i++)
     {
         Camera[] otherCams = new Camera[game.Length-1];
         int j = 0;
         for (int k = 0; k < games.Length-1; k++)
         {
             if (i == j) { j++; }
             otherCams[k] = game[j].cam;
             j++;
         }
         game[i].SetOtherCams(otherCams);
     }
     inputController.GameSetup(game, newGamepad);
 }
Exemplo n.º 3
0
    public void Update()
    {
        string[] joystickNames = Input.GetJoystickNames();

        int countDelta = joystickNames.Length - gamepads.Count;

        if (countDelta > 0)
        {
            //Debug.Log("Just added " + countDelta + " gamepad" + (countDelta == 1 ? "" : "s"));
            while(countDelta > 0)
            {
                countDelta --;
                Gamepad gamepad = new Gamepad(joystickNames[gamepads.Count]);
                Debug.Log("Adding gamepad " + joystickNames[gamepads.Count]);
                gamepads.Add(gamepad);
            }

            isStateCertain = false;
            framesToWaitBeforeCertain = CERTAIN_FRAMES;
        }
        else if(countDelta < 0)
        {
            //Debug.Log("Just removed " + (-countDelta) + " gamepad" + (countDelta == -1 ? "" : "s"));

            while(countDelta < 0)
            {
                countDelta++;
                Debug.Log("Removing gamepad " + gamepads.GetLastObject().index);
                gamepads.Pop();
            }

            isStateCertain = false;
            framesToWaitBeforeCertain = CERTAIN_FRAMES;
        }

        for(int g = 0; g<gamepads.Count; g++)
        {
            gamepads[g].index = g;
            gamepads[g].Update();
        }

        if (isFirstRun) //gamepads should be good at first run
        {
            isFirstRun = false;
            framesToWaitBeforeCertain = 0;
        }

        if (framesToWaitBeforeCertain > 0)
        {
            framesToWaitBeforeCertain--;
            isStateCertain = false;
        }
        else if (framesToWaitBeforeCertain == 0)
        {
            framesToWaitBeforeCertain = -1;

            isStateCertain = true;
        }
    }
Exemplo n.º 4
0
		internal GamepadCollection ( Game Game )
		{
			gamepads	=	new Gamepad[4];
			gamepads[0]	=	new Gamepad( Game.InputDevice.GetGamepad( 0 ) );
			gamepads[1]	=	new Gamepad( Game.InputDevice.GetGamepad( 1 ) );
			gamepads[2]	=	new Gamepad( Game.InputDevice.GetGamepad( 2 ) );
			gamepads[3]	=	new Gamepad( Game.InputDevice.GetGamepad( 3 ) );
		}
Exemplo n.º 5
0
    public void startGame(bool[] isAI, Gamepad[] newGamepads, Transform[] gamesToMake)
    {
        if (gamesToMake.Length == 0) { Application.LoadLevel("MenuScene"); }
        Transform gamectrl;

        gamectrl = Instantiate(gameController);
        GameController ctrl = gamectrl.GetComponent<GameController>();
        ctrl.Initializegames(gamesToMake, isAI, newGamepads);
        SoundManager.Instance.UnmuteMusic();
        SoundManager.Instance.SetMusicFrequency(200);
        Destroy(gameObject);
    }
Exemplo n.º 6
0
    // Use this for initialization
    void Awake()
    {
        sceneName = "Boss";
        popUp = GameObject.Find("SceneManager").GetComponent<DataObjectPopUp>();
        controllerBoss = new ControllerBoss (Boss);
        eventsVerifyBoss = gameObject.GetComponent<EventsVerifyBoss> ();
        eventsVerifyBoss.setController (controllerBoss);

        controllerDino = new ControllerDino(Dino);
        gamepad = gameObject.AddComponent<Gamepad>();
        gamepad.SetController (controllerDino);

        controllerPauseOptions = new ControllerPauseOptions();
        gamepad = gameObject.AddComponent<Gamepad>();
        gamepad.SetController (controllerPauseOptions);
    }
Exemplo n.º 7
0
    public void RunCheck()
    {
        SoundManager.Instance.MuteMusic();
        for (int i = 0; i < subMenus.Length; i++)
        {
            if (subMenus[i].isSelected)
            {
                PressStartText[i].color = new Color(0f, 0f, 0f, 0f);
                Ready[i].color = new Color(0f, 0f, 0f, 255f);
            }
            else
            {
                PressStartText[i].color = new Color(0f, 0f, 0f, 255f);
                Ready[i].color = new Color(0f, 0f, 0f, 0f);
            }

        }
        if (subMenus[0].isSelected && subMenus[1].isSelected && subMenus[2].isSelected && subMenus[3].isSelected)
        {
            int numOfGames = 0;
            for (int i = 0; i < subMenus.Length; i++)
            {
                if (subMenus[i].playertype != 0)
                {
                    numOfGames++;
                }
            }
            bool[] isAI = new bool[numOfGames];
            Gamepad[] newGamepads = new Gamepad[numOfGames];
            Transform[] gamesToMake = new Transform[numOfGames];
            int j = 0;
            for (int i = 0; i < subMenus.Length; i++)
            {

                if (subMenus[i].playertype == 0) { continue; }
                else { newGamepads[j] = gamepads[i]; }
                if (subMenus[i].playertype == 2) { isAI[j] = true; }
                int GametoSet = 0;
                if (subMenus[i].GetSelectGame() == 4) { GametoSet = Random.Range(0, 3); }
                else { GametoSet = subMenus[i].GetSelectGame(); }
                gamesToMake[j] = games[GametoSet];
                j++;
            }
            //gamecol =  new Transform[] { games[subMenus[0].GetSelectGame()], games[subMenus[1].GetSelectGame()], games[subMenus[2].GetSelectGame()], games[subMenus[3].GetSelectGame()]};
            startGame(isAI, newGamepads, gamesToMake);
        }
    }
Exemplo n.º 8
0
        private GamePad()
        {
            _islistening = false;
            var foundpad = false;

            // This is f*****g strange, but it takes 2-3 calls to the Gamepads[] array
            // before anything is returned.
            while (!foundpad)
            {
                try
                {
                    _msftpad = Gamepad.Gamepads[0];
                    foundpad = true;
                }
                catch { }
            }
        }
Exemplo n.º 9
0
        public void Send(Gamepad.GamepadOutput player)
        {
            if (_class.Define.Write == null) return;

            var boolOverride = _class.BaseClass.Home.boolIDE;

            if ((_class.Define.IsConnected() != 1) && !boolOverride) return;

            _class.Define.Write(player.Output);

            var report = new Define.GcapiReportControllermax();
            if (_class.Define.Read(ref report) == IntPtr.Zero) return;

            if (_class.BaseClass.System.UseRumble)
                GamePad.SetState(player.PlayerIndex, report.Rumble[0], report.Rumble[1]);

            //TODO: Read report to see what authenticating controller is doing
        }
Exemplo n.º 10
0
 private void HandleGamepadAdded(object sender, Gamepad gamepad)
 {
     UpdateGamepadList();
 }
Exemplo n.º 11
0
        private void checkButtonState(Controller controller, UserIndex userIndex, Gamepad oldState, GamepadButtonFlags button)
        {
            Gamepad currentState = controller.GetState().Gamepad;

            if ((oldState.Buttons & button) != (currentState.Buttons & button))
            {
                if ((currentState.Buttons & button) != 0)
                {
                    buttonPressed(controller, userIndex, button);
                }
                else
                {
                    buttonReleased(controller, userIndex, button);
                }
            }
        }
Exemplo n.º 12
0
 private void OnGamepadDisconnect(Gamepad gamepad)
 {
     _gamepad = null;
 }
Exemplo n.º 13
0
 public override GamepadHardware createGamepad(Gamepad pad)
 {
     return(RuntimePlatformInfo.CreateGamepadHardware(pad));
 }
Exemplo n.º 14
0
 static void source_Tick()
 {
     #if DEBUG
     sStatistics.Begin();
     #endif
     if (sController != null && sController.IsConnected)
         sGamepad = sController.GetState().Gamepad;
     #if DEBUG
     sStatistics.End();
     #endif
 }
    private void UpdateGamepadState()
    {
        if (GamepadManager.instance.isStateCertain)
        {
            bool wasGamepadNull = (gamepad == null);

            gamepad = GamepadManager.instance.GetGamepad(index);

            if(wasGamepadNull && gamepad != null)
            {
                didJustConnect = true;
            }
            else if(!wasGamepadNull && gamepad == null)
            {
                didJustDisconnect = true;
            }
        }
    }
Exemplo n.º 16
0
    //private List<GameObject> enemiesPositions;
    void Awake()
    {
        sceneName = "Level 0";
        popUp = GameObject.Find("SceneManager").GetComponent<DataObjectPopUp>();
        controllerDino = new ControllerDino(dino, BarraDeFome, 2);
        BarraDeFome.maxValue = dino.GetComponent<DataObjectDino>().InitialFome;

        controllercamera = new ControllerCamera(dino);
        gamepad = gameObject.AddComponent<Gamepad>();
        gamepad.SetController (controllerDino);

        //enemiesPositions = new List<GameObject>(GameObject.FindGameObjectsWithTag("Enemy"));
        //for(int i=0;i<enemiesPositions.Count;i++)
        foreach(GameObject enemy in new List<GameObject>(GameObject.FindGameObjectsWithTag("Spawner")))
        {
            EventsObjects.Add(enemy.name, enemy);
        }

        controllerPauseOptions = new ControllerPauseOptions();
        gamepad = gameObject.AddComponent<Gamepad>();
        gamepad.SetController (controllerPauseOptions);
    }
 public GamepadEvents(Gamepad This)
 {
     this.This = This;
 }
Exemplo n.º 18
0
 private void Gamepad_GamepadAdded(object sender, Gamepad gamepad)
 {
     AddGamepad(gamepad);
 }
Exemplo n.º 19
0
 private void Gamepad_GamepadRemoved(object sender, Gamepad gamepad)
 {
     RemoveGamepad(gamepad);
 }
Exemplo n.º 20
0
 private void Gamepad_GamepadAdded(object sender, Gamepad e)
 {
     gamepad = e;
 }
Exemplo n.º 21
0
 private void Gamepad_GamepadRemoved(object sender, Gamepad e)
 {
     gamepad = null;
 }
Exemplo n.º 22
0
 // Start is called before the first frame update
 void Start()
 {
     playerGamepad = GetComponent <PlayerInput>().GetGamepad();
     isAttacking   = false;
     startAngle    = 0f;
 }
Exemplo n.º 23
0
 private void Gamepad_GamepadUpdated(object sender, Gamepad e)
 {
     GamepadUpdated?.Invoke(this, e);
 }
Exemplo n.º 24
0
 public void Update()
 {
     Gamepad.Update();
 }
Exemplo n.º 25
0
 //-----------------------------------------------------------------------
 public override void DoBeforeNextExecute()
 {
     //This method will be executed each iteration of the script
       connected = XBoxController.IsConnected;
       if (XBoxController.IsConnected == true)
       Controller = XBoxController.GetState().Gamepad;
 }
Exemplo n.º 26
0
 protected override GamepadHardware CreateGamepadHardwareImpl(Gamepad pad)
 {
     return(new AndroidGamepad(pad));
 }
Exemplo n.º 27
0
        public void Update(float dt)
        {
            ThumbstickState old_l = LeftStick;
            ThumbstickState old_r = RightStick;

            // If not connected, nothing to update
            if (!Connected) return;

            if (_vibrationTime > _elapsed)
            {
                _elapsed += dt;
            }
            else
            {
                _elapsed = 0;
                _vibrationTime = 0;
                Vibrate(0, 0);
            }

            // If same packet, nothing to update
            State state = Controller.GetState();
            if (lastPacket == state.PacketNumber) return;
            lastPacket = state.PacketNumber;

            var gamepadState = state.Gamepad;

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

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

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

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

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

            // Thumbsticks
            LeftStick = new ThumbstickState(
                Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0);
            RightStick = new ThumbstickState(
                Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0);

            foreach (var flag in Enum.GetValues(typeof(GamepadButtonFlags)))
            {
                if (OnButtonUp != null)
                    if ((old_state.Buttons & (GamepadButtonFlags)flag) != 0 && (gamepadState.Buttons & (GamepadButtonFlags)flag) == 0)
                        OnButtonUp(this, (GamepadButtons)((GamepadButtonFlags)flag));
                if (OnButtonPress != null)
                {
                    if ((old_state.Buttons & (GamepadButtonFlags)flag) == 0 && (gamepadState.Buttons & (GamepadButtonFlags)flag) != 0)
                        OnButtonPress(this, (GamepadButtons)((GamepadButtonFlags)flag));
                }
                if (OnButtonDown != null)
                    if ((gamepadState.Buttons & (GamepadButtonFlags)flag) != 0)
                        OnButtonDown(this, (GamepadButtons)gamepadState.Buttons);
            }

            if (OnLeftTrigger != null)
                if (gamepadState.LeftTrigger != old_state.LeftTrigger)
                    OnLeftTrigger(this, new TriggerState(LeftTrigger, LeftTrigger - (old_state.LeftTrigger / (float)byte.MaxValue)));
            if (OnRightTrigger != null)
                if (gamepadState.RightTrigger != old_state.RightTrigger)
                    OnRightTrigger(this, new TriggerState(RightTrigger, RightTrigger - (old_state.RightTrigger / (float)byte.MaxValue)));

            if (OnLeftStick != null)
                if (LeftStick.Position != old_l.Position || LeftStick.Clicked != old_l.Clicked)
                    OnLeftStick(this, LeftStick, LeftStick.Position - old_l.Position);
            if (OnRightStick != null)
                if (RightStick.Position != old_r.Position || RightStick.Clicked != old_r.Clicked)
                    OnRightStick(this, RightStick, RightStick.Position - old_r.Position);

            old_state = gamepadState;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Convert DiStates to XInput states.
        /// </summary>
        void UpdateXiStates()
        {
            // Get all mapped devices.
            var settings = SettingsManager.Settings.Items
                           .Where(x => x.MapTo > (int)MapTo.None)
                           .ToArray();

            for (int i = 0; i < settings.Length; i++)
            {
                var setting = settings[i];
                var ud      = SettingsManager.GetDevice(setting.InstanceGuid);
                // If device was not found then continue.
                if (ud == null)
                {
                    continue;
                }
                // If device is offline then continue.
                if (!ud.IsOnline)
                {
                    continue;
                }
                //// If device is not set or test device then...
                //var device = ud.Device;
                //if (device == null)
                //	// Continue loop.
                //	continue;
                var padSetting = SettingsManager.GetPadSetting(setting.PadSettingChecksum);
                // If setting was not found then continue.
                if (padSetting == null)
                {
                    continue;
                }
                var diState = ud.DiState;
                // If custom directInput state is not available then continue.
                if (diState == null)
                {
                    continue;
                }
                // Create GamePad to map to.
                var         gp = new Gamepad();
                bool        success;
                int         index;
                SettingType type;

                // --------------------------------------------------------
                // Convert DInput POV Hat value to D-PAD buttons.
                // --------------------------------------------------------

                // Create array to store 4 buttons for each POV.
                var dPadButtons = new bool[4 * diState.Povs.Length];
                // Loop trough D-Pad button states.
                for (int d = 0; d < diState.Povs.Length; ++d)
                {
                    // Get degree value from the POV.
                    int povdeg = diState.Povs[d];
                    // If POV is pressed into one of the directions then...
                    if (povdeg >= 0)
                    {
                        // Split PoV degrees into 8 groups by
                        // converting PoV degree from 0 to 36000 to number from 0 to 7.
                        // This will allow to have more flexible degree values mapped to buttons.
                        var y = ((2250 + povdeg) / 4500) % 8;
                        // XINPUT_GAMEPAD_DPAD_UP
                        dPadButtons[d * 4 + 0] = (y >= 0 && y <= 1) || y == 7;
                        // XINPUT_GAMEPAD_DPAD_RIGHT
                        dPadButtons[d * 4 + 1] = (y >= 1 && y <= 3);
                        // XINPUT_GAMEPAD_DPAD_DOWN
                        dPadButtons[d * 4 + 2] = (y >= 3 && y <= 5);
                        // XINPUT_GAMEPAD_DPAD_LEFT
                        dPadButtons[d * 4 + 3] = (y >= 5 && y <= 7);
                    }
                }

                // --------------------------------------------------------
                // MAP: D-PAD
                // --------------------------------------------------------

                success = SettingsConverter.TryParseTextValue(padSetting.DPad, out type, out index);
                // If POV index is mapped to the D-PAD
                if (success && index > 0 && type == SettingType.POV)
                {
                    var dPadIndex = index - 1;
                    // --------------------------------------------------------
                    // Target: Button (DPad).
                    // --------------------------------------------------------
                    if (dPadButtons[dPadIndex * 4 + 0])
                    {
                        gp.Buttons |= GamepadButtonFlags.DPadUp;
                    }
                    if (dPadButtons[dPadIndex * 4 + 1])
                    {
                        gp.Buttons |= GamepadButtonFlags.DPadRight;
                    }
                    if (dPadButtons[dPadIndex * 4 + 2])
                    {
                        gp.Buttons |= GamepadButtonFlags.DPadDown;
                    }
                    if (dPadButtons[dPadIndex * 4 + 3])
                    {
                        gp.Buttons |= GamepadButtonFlags.DPadLeft;
                    }
                }

                // --------------------------------------------------------
                // MAP:
                // --------------------------------------------------------

                // Get all mapped items.
                var maps = padSetting.Maps;

                foreach (var map in maps)
                {
                    // If not mapped then continue.
                    if (map.Index == 0)
                    {
                        continue;
                    }

                    // --------------------------------------------------------
                    // MAP Source: Button
                    // --------------------------------------------------------
                    if (map.IsButton)
                    {
                        // If mapped index is in range then...
                        if (map.Index < diState.Buttons.Length)
                        {
                            var pressed = diState.Buttons[map.Index - 1];
                            if (pressed)
                            {
                                // --------------------------------------------------------
                                // Target: Button.
                                // --------------------------------------------------------
                                if (map.Target == TargetType.Button)
                                {
                                    gp.Buttons |= map.ButtonFlag;
                                }
                                // --------------------------------------------------------
                                // Target: Trigger.
                                // --------------------------------------------------------
                                else if (map.Target == TargetType.LeftTrigger)
                                {
                                    gp.LeftTrigger = byte.MaxValue;
                                }
                                else if (map.Target == TargetType.RightTrigger)
                                {
                                    gp.RightTrigger = byte.MaxValue;
                                }
                                // --------------------------------------------------------
                                // Target: Thumb.
                                // --------------------------------------------------------
                                else if (map.Target == TargetType.LeftThumbX)
                                {
                                    gp.LeftThumbX = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                                else if (map.Target == TargetType.LeftThumbY)
                                {
                                    gp.LeftThumbY = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                                else if (map.Target == TargetType.RightThumbX)
                                {
                                    gp.RightThumbX = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                                else if (map.Target == TargetType.RightThumbY)
                                {
                                    gp.RightThumbY = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                            }
                        }
                    }
                    // --------------------------------------------------------
                    // MAP Source: D-PAD button converted from POV.
                    // --------------------------------------------------------
                    else if (map.Type == SettingType.DPOVButton)
                    {
                        // If mapped index is in range then...
                        if (map.Index < dPadButtons.Length)
                        {
                            var pressed = dPadButtons[map.Index - 1];
                            if (pressed)
                            {
                                // --------------------------------------------------------
                                // Target: Button.
                                // --------------------------------------------------------
                                if (map.Target == TargetType.Button)
                                {
                                    gp.Buttons |= map.ButtonFlag;
                                }
                                // --------------------------------------------------------
                                // Target: Trigger.
                                // --------------------------------------------------------
                                else if (map.Target == TargetType.LeftTrigger)
                                {
                                    gp.LeftTrigger = byte.MaxValue;
                                }
                                else if (map.Target == TargetType.RightTrigger)
                                {
                                    gp.RightTrigger = byte.MaxValue;
                                }
                                // --------------------------------------------------------
                                // Target: Thumb.
                                // --------------------------------------------------------
                                else if (map.Target == TargetType.LeftThumbX)
                                {
                                    gp.LeftThumbX = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                                else if (map.Target == TargetType.LeftThumbY)
                                {
                                    gp.LeftThumbY = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                                else if (map.Target == TargetType.RightThumbX)
                                {
                                    gp.RightThumbX = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                                else if (map.Target == TargetType.RightThumbY)
                                {
                                    gp.RightThumbY = map.IsInverted ? short.MinValue : short.MaxValue;
                                }
                            }
                        }
                    }
                    // --------------------------------------------------------
                    // MAP Source: Axis or Slider.
                    // --------------------------------------------------------
                    else if (map.IsAxis || map.IsSlider)
                    {
                        // Get source value.
                        int[] values = map.IsAxis
                            ? diState.Axis
                            : diState.Sliders;

                        // If index is out of range then...
                        if (map.Index > values.Length)
                        {
                            continue;
                        }

                        // Get value.
                        var v = (ushort)values[map.Index - 1];

                        // Destination range.
                        //var min = short.MinValue; // -32768;
                        //var max = short.MaxValue; //  32767;

                        // If value is inverted (I) then...
                        if (map.IsInverted)
                        {
                            // Convert [0;65535] range to [65535;0] range.
                            v = (ushort)(ushort.MaxValue - v);
                        }

                        /// If half value (H) then...
                        //else if (!map.IsInverted && map.IsHalf)
                        //{
                        //	// If value is in [32768;65535] range then...
                        //	v = (v > max)
                        //		// Convert [32768;65535] range to [0;65535] range.
                        //		? (ushort)ConvertHelper.ConvertRange(max + 1, ushort.MaxValue, ushort.MinValue, ushort.MaxValue, v)
                        //		: (ushort)0;
                        //}
                        // If inverted half value (IH) then...
                        //else if (map.IsInverted && map.IsHalf)
                        //{
                        //	// If value is in [0;32767] range then...
                        //	v = (v <= max)
                        //		// Convert [32767;0] range to [0;65535] range.
                        //		? (ushort)ConvertHelper.ConvertRange(max, 0, ushort.MinValue, ushort.MaxValue, v)
                        //		: (ushort)0;
                        //}



                        // --------------------------------------------------------
                        // Target: Button.
                        // --------------------------------------------------------
                        if (map.Target == TargetType.Button)
                        {
                            // If value is inverted (I) then...
                            if (map.IsHalf)
                            {
                                // Map only if [32768;65535];
                                if (v > short.MaxValue)
                                {
                                    v = (ushort)(v + short.MinValue);
                                }
                                else
                                {
                                    v = 0;
                                }
                            }
                            // If axis reached beyond dead zone then...
                            if (v > map.DeadZone)
                            {
                                gp.Buttons |= map.ButtonFlag;
                            }
                        }
                        // --------------------------------------------------------
                        // Target: Trigger.
                        // --------------------------------------------------------
                        else if (map.Target == TargetType.LeftTrigger || map.Target == TargetType.RightTrigger)
                        {
                            var triggerValue = (byte)ConvertHelper.GetThumbValue(v, map.DeadZone, map.AntiDeadZone, map.Linear, map.IsInverted, map.IsHalf, false);
                            if (map.Target == TargetType.LeftTrigger)
                            {
                                gp.LeftTrigger = triggerValue;
                            }
                            if (map.Target == TargetType.RightTrigger)
                            {
                                gp.RightTrigger = triggerValue;
                            }
                        }
                        // --------------------------------------------------------
                        // Target: Thumb.
                        // --------------------------------------------------------
                        else if (map.Target != TargetType.None)
                        {
                            var thumbValue = (short)ConvertHelper.GetThumbValue(v, map.DeadZone, map.AntiDeadZone, map.Linear, map.IsInverted, map.IsHalf);
                            if (map.Target == TargetType.LeftThumbX)
                            {
                                gp.LeftThumbX = thumbValue;
                            }
                            if (map.Target == TargetType.LeftThumbY)
                            {
                                gp.LeftThumbY = thumbValue;
                            }
                            if (map.Target == TargetType.RightThumbX)
                            {
                                gp.RightThumbX = thumbValue;
                            }
                            if (map.Target == TargetType.RightThumbY)
                            {
                                gp.RightThumbY = thumbValue;
                            }
                        }
                    }
                }
                setting.XiState = gp;

                //        [  32768 steps | 32768 steps ]
                // ushort [      0 32767 | 32768 65535 ] DInput
                //  short [ -32768    -1 |     0 32767 ] XInput

                //        [  128 steps | 128 steps ]
                //  byte  [    0   127 | 128   255 ]
                // sbyte  [ -128    -1 |   0   127 ]

                // From Button:    OFF   |     ON
                // From Axis  :      0 - D - 65535 (D - DeadZone)
                //   To Button:    OFF   |     ON

                // From  IAxis:  65535   -      0    x = uint.Max - x;
                // From  HAxis:  32768   -  65535    map only if x >  32768; x = (x - 32768) * 2 + 1;
                // From IHAxis:  32767   -      0    map only if x <= 32767; x = (32767 - x) * 2 + 1;
                // From   Axis:      0   -  65535    x = x;
                //   To Triger:      0   -    255    scale: 255
                //   To   Axis: -32768   -  32767    shift: -32768
            }
            var ev = StatesUpdated;

            if (ev != null)
            {
                ev(this, new DInputEventArgs());
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GamepadAxis"/> class.
 /// </summary>
 /// <param name="gamepad">The gamepad.</param>
 /// <param name="code">The input code.</param>
 /// <param name="name">The input name.</param>
 /// <param name="type">The axis type.</param>
 public GamepadAxis(Gamepad gamepad, int code, string name, AxisType type) : base(gamepad, code, name, type)
 {
     this.Gamepad = gamepad;
 }
Exemplo n.º 30
0
 public void SetAssignedGamepad(Gamepad gp)
 {
     assigned_gamepad = gp;
 }
Exemplo n.º 31
0
 private void OnAcquireGamepad(Gamepad gamepad)
 {
     _gamepad = gamepad;
 }
Exemplo n.º 32
0
 private void Instance_GamepadConnectedCallback(Gamepad gamepad)
 {
     Console.WriteLine("Gamepad connected");
 }
Exemplo n.º 33
0
 public void OnGamepadRemoved(Object o, Gamepad args)
 {
     gamepads.Remove(args);
 }
Exemplo n.º 34
0
 public GamepadWatcher(Gamepad controller)
 {
     _controller = controller ?? throw new ArgumentNullException(nameof(controller));
 }
Exemplo n.º 35
0
        private void TimerGamepad_Elapsed(object sender, ElapsedEventArgs e)
        {
            double VLinMax     = 1; //1.2 ~= 0.3m/s
            double VThetaMax   = 1.5 * Math.PI;
            double valeurRampe = 0.6;
            double Vx;
            double Vy;

            double vitessePriseBalle;

            if (controller.IsConnected)
            {
                gamepad = controller.GetState().Gamepad;

                if (gamepad.LeftThumbY > deadband)
                {
                    Vx = gamepad.LeftThumbY - deadband;
                }
                else if (gamepad.LeftThumbY < -deadband)
                {
                    Vx = gamepad.LeftThumbY + deadband;
                }
                else
                {
                    Vx = 0;
                }
                Vx = Vx / short.MaxValue * VLinMax;

                //Inversion sur Vy pour avoir Vy positif quand on va vers la gauche.
                double gamePadVy = -gamepad.LeftThumbX;
                if (gamePadVy > deadband)
                {
                    Vy = gamePadVy - deadband;
                }
                else if (gamePadVy < -deadband)
                {
                    Vy = gamePadVy + deadband;
                }
                else
                {
                    Vy = 0;
                }
                Vy = Vy / short.MaxValue * VLinMax;


                //Inversion sur VTHeta pour avoir VTheta positif quand on va vers la gauche.
                double gamePadVTheta = -gamepad.RightThumbX;
                if (gamePadVTheta > deadband)
                {
                    Vtheta = gamePadVTheta - deadband;
                }
                else if (gamePadVTheta < -deadband)
                {
                    Vtheta = gamePadVTheta + deadband;
                }
                else
                {
                    Vtheta = 0;
                }
                Vtheta = Vtheta / short.MaxValue * VThetaMax;

                //Console.WriteLine("Gamepad Vx : " + Vx + " Vy : "+Vy +" VTheta : "+Vtheta);
                vitessePriseBalle = (float)(gamepad.RightTrigger) / 2.55;
                if (gamepad.Buttons.HasFlag(GamepadButtonFlags.X))
                {
                    OnTirToRobot(robotId, 50);
                }

                if (gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadUp))
                {
                    OnMoveTirUpToRobot();
                }
                if (gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown))
                {
                    OnMoveTirDownToRobot();
                }
                if (gamepad.Buttons.HasFlag(GamepadButtonFlags.Start))
                {
                    if (stopped)
                    {
                        OnStopToRobot(false);
                        stopped = false;
                    }
                    else
                    {
                        OnStopToRobot(true);
                        stopped = true;
                    }
                }


                if (useRampe)
                {
                    if (Vx >= VxRampe)
                    {
                        VxRampe += valeurRampe;
                        VxRampe  = Math.Min(VxRampe, Vx);
                    }
                    else
                    {
                        VxRampe -= valeurRampe;
                        VxRampe  = Math.Max(VxRampe, Vx);
                    }

                    if (Vy >= VyRampe)
                    {
                        VyRampe += valeurRampe;
                        VyRampe  = Math.Min(VyRampe, Vy);
                    }
                    else
                    {
                        VyRampe -= valeurRampe;
                        VyRampe  = Math.Max(VyRampe, Vy);
                    }

                    if (Vtheta >= VthetaRampe)
                    {
                        VthetaRampe += valeurRampe;
                        VthetaRampe  = Math.Min(VthetaRampe, Vtheta);
                    }
                    else
                    {
                        VthetaRampe -= valeurRampe;
                        VthetaRampe  = Math.Max(VthetaRampe, Vtheta);
                    }
                }
                else
                {
                    VxRampe     = Vx;
                    VyRampe     = Vy;
                    VthetaRampe = Vtheta;
                }

                OnSpeedConsigneToRobot(robotId, VxRampe, VyRampe, VthetaRampe);
                //OnPriseBalleToRobot(2, (float)(Vx*33.3));
                OnPriseBalleToRobot(5, vitessePriseBalle);
                OnPriseBalleToRobot(6, -vitessePriseBalle);
            }
        }
        public void UpdateVirtualKeyboard(Gamepad pad)
        {
            // Get the shift flag.
            vkshiftkey = (pad.RightTrigger > 10 || pad.LeftTrigger > 10) ? true : false;

            // get the actual cursor moving parameter.
            // 0.7.11: also use thumbsticks
            float dzone      = Program.Input.deadzone;
            int   moveCursor = -1;

            if ((pad.Buttons & GamepadButtonFlags.DPadUp) == GamepadButtonFlags.DPadUp ||
                pad.LeftThumbY > dzone || pad.RightThumbY > dzone)
            {
                moveCursor = 1; // up
            }
            if ((pad.Buttons & GamepadButtonFlags.DPadDown) == GamepadButtonFlags.DPadDown ||
                pad.LeftThumbY < -dzone || pad.RightThumbY < -dzone)
            {
                moveCursor = 2; // down
            }
            if ((pad.Buttons & GamepadButtonFlags.DPadLeft) == GamepadButtonFlags.DPadLeft ||
                pad.LeftThumbX < -dzone || pad.RightThumbX < -dzone)
            {
                moveCursor = 3; // left
            }
            if ((pad.Buttons & GamepadButtonFlags.DPadRight) == GamepadButtonFlags.DPadRight ||
                pad.LeftThumbX > dzone || pad.RightThumbX > dzone)
            {
                moveCursor = 4;     // right
            }
            // set the y cursor position directly
            // with the shortcut keys. And then press.
            if ((pad.Buttons & GamepadButtonFlags.RightShoulder) == GamepadButtonFlags.RightShoulder)
            {
                moveCursor = 9;
            }
            if ((pad.Buttons & GamepadButtonFlags.A) == GamepadButtonFlags.A)
            {
                moveCursor = 8;
            }
            if ((pad.Buttons & GamepadButtonFlags.B) == GamepadButtonFlags.B)
            {
                moveCursor = 7;
            }
            if ((pad.Buttons & GamepadButtonFlags.X) == GamepadButtonFlags.X)
            {
                moveCursor = 6;
            }
            if ((pad.Buttons & GamepadButtonFlags.Y) == GamepadButtonFlags.Y)
            {
                moveCursor = 5;
            }

            // or hit the key under the cursor directly with LS.
            if ((pad.Buttons & GamepadButtonFlags.LeftShoulder) == GamepadButtonFlags.LeftShoulder)
            {
                moveCursor = 10;
            }

            // update the cursor position, but just once.
            if (moveCursor != lastVKCursorKey ||
                (VKfirsttime == false && VKtimer > 60) ||
                (VKfirsttime == true && VKtimer > 250))
            {
                switch (moveCursor)
                {
                case 1:     // up
                    vkPosY -= 1;
                    if (vkPosY < 0)
                    {
                        vkPosY = vkMaxY - 1;
                    }
                    break;

                case 2:     // down
                    vkPosY += 1;
                    if (vkPosY >= vkMaxY)
                    {
                        vkPosY = 0;
                    }
                    break;

                case 3:     // left
                    vkPosX -= 1;
                    if (vkPosX < 0)
                    {
                        vkPosX = vkMaxX - 1;
                    }
                    break;

                case 4:     // right
                    vkPosX += 1;
                    if (vkPosX >= vkMaxX)
                    {
                        vkPosX = 0;
                    }
                    break;

                // special shortcut cursor
                // positions with a direct keyhit.
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                    vkPosY = moveCursor - 5;
                    hitCursor();
                    break;

                case 10:
                    hitCursor();
                    break;

                default:
                    break;
                }
                // reset timer.
                VKtimer = 0;
                // reset the first timer only
                // if another key is pressed.
                if (moveCursor == lastVKCursorKey)
                {
                    VKfirsttime = false;
                }
                else
                {
                    VKfirsttime = true;
                }
            }
            lastVKCursorKey = moveCursor;
            VKtimer        += 20;
            Program.UpdateVKForm(vkshiftkey, vkPosX, vkPosY);
        }
Exemplo n.º 37
0
 private void Start()
 {
     gamepads    = new Gamepad[2];
     gamepads[0] = new Gamepad();
     gamepads[1] = new Gamepad();
 }
 public void GameSetup(GameClass[] games, Gamepad[] newGamepads)
 {
     game = games;
     gamepads = newGamepads;
 }
Exemplo n.º 39
0
 internal GamepadDPad(Gamepad gamepad, PlayerIndex? playerIndex = null)
 {
     this.gamepad = gamepad;
     this.playerIndex = playerIndex;
 }
Exemplo n.º 40
0
        private void inputAdquireTimer_Tick(object sender, EventArgs e)
        {
            if (gamepadConnected == false || controller.IsConnected == false)
            {
                return;
            }

            gamepad = controller.GetState().Gamepad;
            controller.SetVibration(new Vibration()
            {
                LeftMotorSpeed = (ushort)(65535 * (gamepad.LeftTrigger / 255)), RightMotorSpeed = (ushort)(65535 * (gamepad.RightTrigger / 255))
            });

            motorPower += gamepad.RightTrigger * 0.01f;
            motorPower -= gamepad.LeftTrigger * 0.01f;

            if (gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
            {
                motorPower -= 10;
            }
            if (motorPower < 0)
            {
                motorPower = 0;
            }
            if (motorPower > 100)
            {
                motorPower = 100;
            }

            trackBarThrottle.Value = (int)motorPower;


            //Do axis goals
            if (gamepad.LeftThumbX == -32768)
            {
                gamepad.LeftThumbX = -32767;
            }
            if (gamepad.LeftThumbY == -32768)
            {
                gamepad.LeftThumbY = -32767;
            }
            if (gamepad.RightThumbX == -32768)
            {
                gamepad.RightThumbX = -32767;
            }
            if (gamepad.RightThumbY == -32768)
            {
                gamepad.RightThumbY = -32767;
            }

            if (Math.Abs(gamepad.LeftThumbX) < 5000)
            {
                rollGoal = 0;
            }
            else
            {
                if (gamepad.LeftThumbY > 0)
                {
                    rollGoal = Map(gamepad.LeftThumbX, 5000, 32790, 0, 20);
                }
                else
                {
                    rollGoal = Map(gamepad.LeftThumbX, -32790, -5000, -20, 0);
                }
            }

            if (Math.Abs(gamepad.LeftThumbY) < 5000)
            {
                pitchGoal = 0;
            }
            else
            {
                if (gamepad.LeftThumbY > 0)
                {
                    pitchGoal = Map(gamepad.LeftThumbY, 5000, 32790, 0, 20);
                }
                else
                {
                    pitchGoal = Map(gamepad.LeftThumbY, -32790, -5000, -20, 0);
                }
            }


            if (Math.Abs(gamepad.RightThumbX) > 5000)
            {
                if (gamepad.RightThumbX > 0)
                {
                    yawGoal += Map(gamepad.RightThumbX, 5000, 32767, 0, 2.1f);
                }
                else
                {
                    yawGoal += Map(gamepad.RightThumbX, -32790, -5000, -2.1f, 0);
                }
            }

            yawGoal = yawGoal % 360;
            if (yawGoal < 0)
            {
                yawGoal += 360;
            }
        }
Exemplo n.º 41
0
        public void DeclareClasses(BaseClass baseClass)
        {
            BaseClass = baseClass;
            Main = baseClass.Home;

            Debug = new Debug();
            Profile = new Profile(this);
            Set = new Set(this);
            Var = new Var(this);
            Xml = new XmlData(this);
            Log = new Log();
            Settings = new Settings(this);
            Gamepad = new Gamepad(this);
            Display = new Display(this);
            TitanOneConfig = new TitanOne(this);
            ControllerMaxConfig = new ControllerMax(this);
            Vr = new Vr(this);
        }
Exemplo n.º 42
0
 public XBox360PluginGlobal(UserIndex index)
 {
     controller = new Controller(index);
     pad = new Gamepad();
 }
Exemplo n.º 43
0
 void Awake()
 {
     controllerMenuButtons = new ControllerExitButtons();
     gamepad = GetComponent<Gamepad>();
     gamepad.SetController(controllerMenuButtons);
 }
Exemplo n.º 44
0
 void Awake()
 {
     controllerCredits = new ControllerCredits ();
     gamepad = GetComponent<Gamepad> ();
     gamepad.SetController (controllerCredits);
 }
Exemplo n.º 45
0
 void Start()
 {
     gamepad        = Gamepad.current;
     follow         = GetComponent <PathFollower>();
     playerCollider = GetComponent <Collider>();
 }
Exemplo n.º 46
0
 /// <summary>
 /// Creates a GamepadHardware object that manipulates the given Gamepad.
 /// </summary>
 /// <returns>The new gamepad.</returns>
 public abstract GamepadHardware createGamepad(Gamepad pad);
Exemplo n.º 47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GamepadButton"/> class.
 /// </summary>
 /// <param name="gamepad">The gamepad.</param>
 /// <param name="code">The button code.</param>
 /// <param name="name">The button name.</param>
 public GamepadButton(Gamepad gamepad, int code, string name) : base(gamepad, code, name)
 {
     this.Gamepad = gamepad;
 }
Exemplo n.º 48
0
 public XBox360PluginGlobal(UserIndex index)
 {
     controller = new Controller(index);
     pad        = new Gamepad();
 }
Exemplo n.º 49
0
 internal void Update()
 {
     if (controller.IsConnected) 
         pad = controller.GetState().Gamepad;
 }
Exemplo n.º 50
0
 public static Vector2 Get(AirVRCameraRig cameraRig, Gamepad.Axis2D axis)
 {
     return(GetAxis2D(cameraRig, AirVRInputDeviceName.Gamepad, Gamepad.ParseControlID(axis)));
 }
Exemplo n.º 51
0
 internal GamepadThumbsticks(Gamepad gamepad, PlayerIndex? playerIndex = null)
 {
     this.gamepad = gamepad;
     this.playerIndex = playerIndex;
 }
Exemplo n.º 52
0
 public static float Get(AirVRCameraRig cameraRig, Gamepad.Axis axis)
 {
     return(GetAxis(cameraRig, AirVRInputDeviceName.Gamepad, Gamepad.ParseControlID(axis)));
 }
Exemplo n.º 53
0
 void Awake()
 {
     controllerOptionsButtons = new ControllerOptionsButtons();
     gamepad = GetComponent<Gamepad> ();
     gamepad.SetController(controllerOptionsButtons);
 }
Exemplo n.º 54
0
 public static bool GetUp(AirVRCameraRig cameraRig, Gamepad.Button button)
 {
     return(GetButtonUp(cameraRig, AirVRInputDeviceName.Gamepad, Gamepad.ParseControlID(button)));
 }
Exemplo n.º 55
0
        // [Menu]
        public void SetGamepad(Gamepad gamepad)
        {
            Gamepad = gamepad;

            // TODO: we should listen for the device disconnecting so we can release it
        }
Exemplo n.º 56
0
 private async void Gamepad_GamepadAdded(object sender, Gamepad e)
 {
     await Log("Controller Added");
 }
Exemplo n.º 57
0
 //-----------------------------------------------------------------------
 public override void DoBeforeNextExecute()
 {
     //This method will be executed each iteration of the script
      Controller = XBoxController.GetState().Gamepad;
 }
Exemplo n.º 58
0
    public void CustomUpdate()
    {
        var deadzone = 0.2f;
        // Hard-coded controls for now
        //var gamepad = Gamepad.current;
        //if (gamepad == null)
        // return; // No gamepad connected
        //gamepad.leftStick.x.ReadValue() >= deadzone
        // Player One


        // P1 gets gamepad.

        /*
         * var p1Controls = new MyControls();
         * p1Controls.devices = new[] { Gamepad.all[0] };
         * p1Controls.bindingMask = InputBinding.MaskByGroup("Gamepad");
         * p1Controls.Enable();
         */

        // P2 gets keyboard&mouse.

        /*
         * var p2Controls = new MyControls();
         * p2Controls.devices = new[] { Keyboard.current, Mouse.current };
         * p2Controls.bindingMask = InputBinding.MaskByGroup("KeyboardMouse");
         * p2Controls.Enable();
         */
        var keyboard_right     = false;
        var keyboard_left      = false;
        var keyboard_up        = false;
        var keyboard_down      = false;
        var keyboard_primary   = false;
        var keyboard_secondary = false;

        //Debug.Log(myInputActionAsset.FindAction("Player/Move", true).phase == InputActionPhase.Started);
        var axis    = myInputActionAsset.FindAction("Player/Move", true).ReadValue <Vector2>();
        var primary = myInputActionAsset.FindAction("Player/Primary", true).ReadValue <float>();
        var jump    = myInputActionAsset.FindAction("Player/Jump", true).ReadValue <float>();
        var walk    = 1f - myInputActionAsset.FindAction("Player/Walk", true).ReadValue <float>();

        //return;
        //var gamepad = new InputControls();
        //gamepad.devices = new[] { Gamepad.all[0] };
        //Debug.Log(Gamepad.all);



        var     isGamepad = Gamepad.all.Count != 0;
        Gamepad gamepad   = null;

        if (isGamepad)
        {
            gamepad = Gamepad.all[0];
        }
        // var keyboard = Keyboard.current;
        //var myControls = new InputControls();
        //myControls.devices = new InputDevice[] { Keyboard.current };
        //myControls.bindingMask = InputBinding.MaskByGroup("Player");
        //myControls.Enable();
        //if (
        //InputAction primaryAction = myInputActionAsset.FindAction("PrimaryAction", true);



        //Debug.Log(InputHandler.inputs[0].inAxis[(int)InputContainer.Axis.LEFT_HORIZONTAL].val);
        if (gamepad != null)
        {
            InputHandler.inputs[0].inAxis[0].val = gamepad.leftStick.x.ReadValue();
            InputHandler.inputs[0].inAxis[1].val = gamepad.leftStick.y.ReadValue();
        }
        else
        {
            InputHandler.inputs[0].inAxis[0].val = axis.x * Mathf.Clamp(walk, 0.3f, 1f);
            InputHandler.inputs[0].inAxis[1].val = axis.y;
        }



        // Update Left stick
        if ((gamepad != null && gamepad.leftStick.x.ReadValue() >= deadzone) || axis.x > 0)
        {
            InputHandler.inputs[0].Press(InputContainer.Button.IN_RIGHT);
        }
        else
        {
            InputHandler.inputs[0].Release(InputContainer.Button.IN_RIGHT);
        }

        if ((gamepad != null && gamepad.leftStick.x.ReadValue() <= -deadzone) || axis.x < 0)
        {
            InputHandler.inputs[0].Press(InputContainer.Button.IN_LEFT);
        }
        else
        {
            InputHandler.inputs[0].Release(InputContainer.Button.IN_LEFT);
        }

        if ((gamepad != null && gamepad.leftStick.y.ReadValue() <= -deadzone) || axis.y < 0)
        {
            InputHandler.inputs[0].Press(InputContainer.Button.IN_DOWN);
        }
        else
        {
            InputHandler.inputs[0].Release(InputContainer.Button.IN_DOWN);
        }


        // Temp keyboard controls



        // Update Jump Button
        if (gamepad != null && (gamepad.xButton.isPressed || gamepad.yButton.isPressed) || jump == 1f)
        {
            InputHandler.inputs[0].Press(InputContainer.Button.IN_JUMP);
        }
        else
        {
            InputHandler.inputs[0].Release(InputContainer.Button.IN_JUMP);
        }


        // Update Attack/Primary button
        if ((gamepad != null && gamepad.aButton.isPressed) || primary == 1f)
        {
            InputHandler.inputs[0].Press(InputContainer.Button.IN_PRIMARY);
        }
        else
        {
            InputHandler.inputs[0].Release(InputContainer.Button.IN_PRIMARY);
        }
    }
Exemplo n.º 59
0
 internal GamepadTriggerPair(Gamepad gamepad, PlayerIndex? playerIndex = null)
 {
     this.gamepad = gamepad;
     this.playerIndex = playerIndex;
 }
Exemplo n.º 60
0
        private void ComputeXboxFoV( Gamepad gamepad )
        {
            if( Camera == null )
            {
                return;
            }

            byte lt = gamepad.LeftTrigger;
            byte rt = gamepad.RightTrigger;

            // do nothing if both triggers are held down
            if( lt > 0 && rt > 0 )
            {
                return;
            }
            
            float fov = Camera.FieldOfView;            

            // left trigger: zoom out
            if( lt > 0 )
            {
                fov += lt * XboxGamepadParameters.FoVRadiansPerTick;
            }
            // right trigger: zoom in
            else
            {
                fov -= rt * XboxGamepadParameters.FoVRadiansPerTick;  
            }

            fov = fov.Clamp( Arithmetic.DegreesToRadians( 1 ), Arithmetic.DegreesToRadians( 179 ) );
            Camera.FieldOfView = fov;
        }