Exemple #1
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            _gamepad = XNAInput.GamePad.GetState((PlayerIndex)Index);

            base.Update(gameTime);

            MapButtonValue(_previousGamepad.Buttons.A, _gamepad.Buttons.A, MappingButtons.A);
            MapButtonValue(_previousGamepad.Buttons.B, _gamepad.Buttons.B, MappingButtons.B);
            MapButtonValue(_previousGamepad.Buttons.X, _gamepad.Buttons.X, MappingButtons.X);
            MapButtonValue(_previousGamepad.Buttons.Y, _gamepad.Buttons.Y, MappingButtons.Y);
            MapButtonValue(_previousGamepad.Buttons.Back, _gamepad.Buttons.Back, MappingButtons.Back);
            MapButtonValue(_previousGamepad.Buttons.Start, _gamepad.Buttons.Start, MappingButtons.Start);
            MapButtonValue(_previousGamepad.Buttons.BigButton, _gamepad.Buttons.BigButton, MappingButtons.Home);
            MapButtonValue(_previousGamepad.Buttons.LeftShoulder, _gamepad.Buttons.LeftShoulder, MappingButtons.LB);
            MapButtonValue(_previousGamepad.Buttons.RightShoulder, _gamepad.Buttons.RightShoulder, MappingButtons.RB);

            // Thumbsticks
            // ndDam: no stick "clic" for now
            ThumbStickLeft.X = _gamepad.ThumbSticks.Left.X;
            ThumbStickLeft.Y = _gamepad.ThumbSticks.Left.Y;

            ThumbStickRight.X = _gamepad.ThumbSticks.Right.X;
            ThumbStickRight.Y = _gamepad.ThumbSticks.Right.Y;

            _previousGamepad = _gamepad;
        }
Exemple #2
0
 private void UpdateDPadButtons(XnaInput.GamePadState state)
 {
     UpdateButton(state.DPad.Down, GamePadButton.Down);
     UpdateButton(state.DPad.Up, GamePadButton.Up);
     UpdateButton(state.DPad.Left, GamePadButton.Left);
     UpdateButton(state.DPad.Right, GamePadButton.Right);
 }
Exemple #3
0
 static Input()
 {
     oldGamePadStates = new GamePadState[MaxInputs];
     newGamePadStates = new GamePadState[MaxInputs];
     //oldKeyboardState = new KeyboardState[MaxInputs];
     //newKeyboardState = new KeyboardState[MaxInputs];
 }
Exemple #4
0
 private void UpdateStickAndShoulderButtons(XnaInput.GamePadState state)
 {
     UpdateButton(state.Buttons.LeftShoulder, GamePadButton.LeftShoulder);
     UpdateButton(state.Buttons.LeftStick, GamePadButton.LeftStick);
     UpdateButton(state.Buttons.RightShoulder, GamePadButton.RightShoulder);
     UpdateButton(state.Buttons.RightStick, GamePadButton.RightStick);
 }
 /// <summary>
 /// Handles input, performs physics, and animates the player sprite.
 /// </summary>
 /// <remarks>
 /// We pass in all of the input states so that our game is only polling the hardware
 /// once per frame. We also pass the game's orientation because when using the accelerometer,
 /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
 /// </remarks>
 public void Update(
     GameTime gameTime,
     KeyboardState keyboardState,
     GamePadState gamePadState)
 {
     base.Update(gameTime);
 }
Exemple #6
0
        protected void AmbientToggle(KeyboardState currentKeyboardState, GamePadState currentGamePadState)
        {
            // toggle Ambient - Night/Day effect
            if (previousKeyboardState.IsKeyDown(Keys.E) &&
                currentKeyboardState.IsKeyUp(Keys.E) ||
                previousGamePadState.IsButtonDown(Buttons.RightShoulder) &&
                currentGamePadState.IsButtonUp(Buttons.RightShoulder))
            {
                ambient = !ambient;

                currentMusic.Stop();
                currentMusic.Dispose();

                // Ambient true sets to day time effect, false sets to night time effect
                if(ambient)
                {
                    skyColor = Color.DeepSkyBlue;
                    effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.65f, 0.65f, 0.6f, 1.0f));
                    currentMusic = musicDay.CreateInstance();

                }
                else
                {
                    skyColor = Color.DarkSlateGray;
                    effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.1f, 0.1f, 0.15f, 1.0f));
                    currentMusic = musicNight.CreateInstance();
                }
                enemy.Apply3DAudio(listener, enemy.Position, currentMusic);
                currentMusic.Play();

            }
        }
        /// <summary>
        /// Exit the screen after a tap or click
        /// </summary>
        /// <param name="input"></param>
        private void HandleInput(MouseState mouseState, GamePadState padState)
        {
            if (!isExit)
            {
#if WINDOWS_PHONE
                if (ScreenManager.input.Gestures.Count > 0 &&
                    ScreenManager.input.Gestures[0].GestureType == GestureType.Tap)
                {
                    isExit = true;
                }
#else

                PlayerIndex result;
                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    isExit = true;
                }
                else if (ScreenManager.input.IsNewButtonPress(Buttons.A, null, out result) ||
                    ScreenManager.input.IsNewButtonPress(Buttons.Start, null, out result))
                {
                    isExit = true;
                }
#endif

            }
        }
        public void Update(GameTime gameTime)
        {
            oldGs = gamePadState;

            gamePadState = GamePad.GetState(playerIndex, GamePadDeadZone.None);
            gamePadChanged = gamePadState != oldGs;
        }
Exemple #9
0
        /// <summary>
        /// Gets the current direction from a game pad and keyboard.
        /// </summary>
        public static Buttons FromInput(GamePadState gamePad, KeyboardState keyboard)
        {
            Buttons direction = None;

            // Get vertical direction.
            if (gamePad.IsButtonDown(Buttons.DPadUp) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickUp) ||
                keyboard.IsKeyDown(Keys.Up))
            {
                direction |= Up;
            }
            else if (gamePad.IsButtonDown(Buttons.DPadDown) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickDown) ||
                keyboard.IsKeyDown(Keys.Down))
            {
                direction |= Down;
            }

            // Comebine with horizontal direction.
            if (gamePad.IsButtonDown(Buttons.DPadLeft) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickLeft) ||
                keyboard.IsKeyDown(Keys.Left))
            {
                direction |= Left;
            }
            else if (gamePad.IsButtonDown(Buttons.DPadRight) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickRight) ||
                keyboard.IsKeyDown(Keys.Right))
            {
                direction |= Right;
            }

            return direction;
        }
Exemple #10
0
 //********************************************
 // Constructors
 //********************************************
 public InputManager(Main game)
 {
     z_game = game;
     z_prevKeyState = z_curKeyState = new KeyboardState();
     z_prevPadState = z_curPadState = new GamePadState();
     SetDefaultControls();
 }
Exemple #11
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            previousGamePadState = GamePad.GetState(PlayerIndex.One);
        }
Exemple #12
0
 public float getAxis(GamePadState gamePadState, bool left, bool x)
 {
     if (x)
     {
         if (left)
         {
             return gamePadState.ThumbSticks.Left.X;
         }
         else
         {
             return gamePadState.ThumbSticks.Right.X;
         }
     }
     else
     {
         if (left)
         {
             return gamePadState.ThumbSticks.Left.Y;
         }
         else
         {
             return gamePadState.ThumbSticks.Right.Y;
         }
     }
 }
Exemple #13
0
        //Methods
        //Update & Draw
        public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState)
        {
            if (keyboard.IsKeyUp(Keys.Escape) && gamePadState.Buttons.Start == ButtonState.Released)
                pauseAllowed = true;

            if ((keyboard.IsKeyDown(Keys.Escape) || gamePadState.Buttons.Start == ButtonState.Pressed) && pauseAllowed)
            {

                pauseAllowed = false;
                Game1.gameState = GameState.Pause;
            }

            if (mouse.X > 800)
            {
                Map.Current.position.X++;
                player.position.X++;
            }

            if (mouse.X < 200)
            {
                Map.Current.position.X--;
                player.position.X--;
            }

            Map.Current.Update();
            player.Update(mouse, keyboard, gamePadState);
        }
Exemple #14
0
        public virtual void GamePadController(GamePadState state)
        {
            if (state.DPad.Down == ButtonState.Pressed && !(_previousGamePadState.DPad.Down == ButtonState.Pressed))
            {
                _selectedIndex++;

                if (_selectedIndex == _levels.Length)
                    _selectedIndex--;
            }
            else if (state.DPad.Up == ButtonState.Pressed && !(_previousGamePadState.DPad.Up == ButtonState.Pressed))
            {
                _selectedIndex--;

                if (_selectedIndex < 0)
                    _selectedIndex++;
            }
            else if (state.Buttons.A == ButtonState.Pressed &&!(_previousGamePadState.Buttons.A ==ButtonState.Pressed))
            {
                var sample = _levels[_selectedIndex].CreateLevelFunction();
                sample.OnLoad();
                CurrentLevel = sample;
            }

            _previousGamePadState = state;
        }
Exemple #15
0
        public override void CaptureMouseState()
        {
            _gpState = XInput.GamePad.GetState( XFG.PlayerIndex.One );

            relativeMousePosition.X = _gpState.ThumbSticks.Left.X;
            relativeMousePosition.Y = _gpState.ThumbSticks.Left.Y;
        }
        private List<Command> handleController()
        {
            List<Command> commands = new List<Command>();
            padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
            
            Vector2 move = new Vector2();
            move.X = 0;
            move.Y = 0;
            if (padState.ThumbSticks.Left.Length() > .7f)
            {
                move.X = padState.ThumbSticks.Left.X * .7f;
                move.Y = -padState.ThumbSticks.Left.Y * .7f;   
            }
            commands.Add(new MoveCommand(move));


            Vector2 gazeDir = new Vector2();
            gazeDir.X = padState.ThumbSticks.Right.X;
            gazeDir.Y = -padState.ThumbSticks.Right.Y;
            commands.Add(new GazeCommand(gazeDir));

            if (padState.IsButtonDown(Buttons.RightShoulder))
                commands.Add(new PunchCommand());
            return commands;
        }
 public override void Update(GameTime gameTime, GamePadState newGamePadState, GamePadState oldGamePadState, KeyboardState newKeyboardState, KeyboardState oldKeyboardState)
 {
     if ((newGamePadState.Buttons.A != oldGamePadState.Buttons.A && newGamePadState.Buttons.A == ButtonState.Pressed)
         || (newKeyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter))) {
         Game.GameStartingScreen = GameStartingScreen.SetupScreen;
     }
 }
        // Adds an attack when the attack button is pressed accompanied by sound and animation
        public static void AttackAdd(ContentManager Content, Player ninja, List<PlayerAttack> ninjaAttacks, 
            KeyboardState presentKey, KeyboardState pastKey,
            GamePadState pressentButton, GamePadState pastButton)
        {
            if (presentKey.IsKeyDown(Keys.Space) && pastKey.IsKeyUp(Keys.Space)
                || pressentButton.IsButtonDown(Buttons.A) && pastButton.IsButtonUp(Buttons.A))
            {
                // if the attack button is pressed a new attack will be added to the list
                ninjaAttacks.Add(new PlayerAttack(Content.Load<Texture2D>("Images\\Attack"),
                    new Vector2(ninja.PositionX + (int)(ninja.Texture.Width * 0.8),
                    ninja.PositionY + (int)(ninja.Texture.Height / 2.25))));

                // A sound effect will be played each time we press the attack button
                ninja.PlaySound();

            }

            // The animation texture of the character will change with each attack
            if (presentKey.IsKeyDown(Keys.Space) || pressentButton.IsButtonDown(Buttons.A))
            {
                ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-2");
            }
            else
            {
                ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-1");
            }
        }
Exemple #19
0
        public static List<InputManager.ACTIONS> GetInput()
        {
            currentGamePadState = GamePad.GetState(PlayerIndex.One);
            List<InputManager.ACTIONS> actions = new List<InputManager.ACTIONS>();

            if (currentGamePadState.IsButtonUp(Buttons.A) && previousGamePadState.IsButtonDown(Buttons.A))
            {
                actions.Add(InputManager.ACTIONS.JUMP);
            }

            if (currentGamePadState.ThumbSticks.Left.X > 0 || currentGamePadState.DPad.Right == ButtonState.Pressed)
            {
                actions.Add(InputManager.ACTIONS.RIGHT);
            }
            else if (currentGamePadState.ThumbSticks.Left.X < 0 || currentGamePadState.DPad.Left == ButtonState.Pressed)
            {
                actions.Add(InputManager.ACTIONS.LEFT);
            }

            if (currentGamePadState.IsButtonUp(Buttons.Y) && previousGamePadState.IsButtonDown(Buttons.Y))
            {
                actions.Add(InputManager.ACTIONS.TOGGLE);
            }

            previousGamePadState = currentGamePadState;
            return actions;
        }
Exemple #20
0
        public void UpdateJump(KeyboardState aCurrentKeyboardState, GamePadState aCurrentGamePadState)
        {
            if ((CurrentState == State.Walking || CurrentState == State.Still) && (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true || aCurrentGamePadState.DPad.Up == ButtonState.Pressed || aCurrentGamePadState.Buttons.A == ButtonState.Pressed))
            {
                Jump();
            }

            if (CurrentState == State.Jumping)
            {

                if (StartPosition.Y - Position.Y > 80)  //At peak of jump...
                {
                    Dir.Y = MOVE_DOWN;
                    MoveSpeed.Y = 3.0f;
                }

                Position.Y = (Dir.Y == MOVE_DOWN) ? Position.Y + MoveSpeed.Y : Position.Y - MoveSpeed.Y; //Change Y position

                //END JUMP LOGIC
                if (Position.Y > StartPosition.Y)
                {
                    Position.Y = StartPosition.Y;
                    CurrentState = State.Still;
                    Source = new Rectangle(0, 0, 28, Source.Height);
                    Dir.Y = 0;
                    MoveSpeed.X = 6.0f;
                    MoveSpeed.Y = 3.5f;
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// Updates key and pad states and also action values
        /// </summary>
        public void update()
        {
            keyState = Keyboard.GetState();
            padState = GamePad.GetState(index);

            foreach (Action action in actionList)
            {
                if (keyState.IsKeyDown(action.key) ||
                            padState.IsButtonDown(action.button))
                {
                    action.isPressed = true;
                    action.pressTime += 1;
                }
                else if ((keyState.IsKeyUp(action.key) &&
                                prevKeyState.IsKeyDown(action.key))
                        || (padState.IsButtonUp(action.button) &&
                                prevPadState.IsButtonDown(action.button)))
                {
                    action.isPressed = false;
                    action.pressTime = 0;
                };
            }
            //Last run - store the current states
            //as the previous state
            prevKeyState = keyState;
            prevPadState = padState;
        }
        public void ProcessController()
        {
            keyState = Keyboard.GetState();
            padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
            Actor hero = (Actor)game.Hero;

            /*
             * GamePad inputs
             */

            //Moving
            if (padState.IsButtonDown(Buttons.LeftThumbstickLeft) || keyState.IsKeyDown(Keys.Left))
            {
                hero.Pos.X -= 1.5f;
                hero.NextPosture(ActorDirection.Left);
            }
            if (padState.IsButtonDown(Buttons.LeftThumbstickRight) || keyState.IsKeyDown(Keys.Right))
            {
                hero.Pos.X += 1.5f;
                hero.NextPosture(ActorDirection.Right);
            }

            //Jump
            if (padState.IsButtonDown(Buttons.LeftThumbstickUp))
            {

            }

            if (padState.IsButtonDown(Buttons.LeftThumbstickDown))
            {

            }
        }
Exemple #23
0
 public void update(GamePadState gamePad, GameTime time)
 {
     if (! Menu.isActive())
     {
         if (time.TotalGameTime.Milliseconds % 50 == 0)
         {
             if (gamePad.ThumbSticks.Left.X > 0 && position.X < maxPosition.X)
                 position.X += cursorWidth;
             else if (gamePad.ThumbSticks.Left.X < 0 && position.X > 0)
                 position.X -= cursorWidth;
             if (gamePad.ThumbSticks.Left.Y < 0 && position.Y < maxPosition.Y)
                 position.Y += cursorHeight;
             else if (gamePad.ThumbSticks.Left.Y > 0 && position.Y > 0)
                 position.Y -= cursorHeight;
         }
         if (time.TotalGameTime.Milliseconds % 200 == 0)
         {
             if (gamePad.DPad.Right == ButtonState.Pressed && position.X < maxPosition.X)
                 position.X += cursorWidth;
             else if (gamePad.DPad.Left == ButtonState.Pressed && position.X > 0)
                 position.X -= cursorWidth;
             if (gamePad.DPad.Down == ButtonState.Pressed && position.Y < maxPosition.Y)
                 position.Y += cursorHeight;
             else if (gamePad.DPad.Up == ButtonState.Pressed && position.Y > 0)
                 position.Y -= cursorHeight;
         }
     }
 }
Exemple #24
0
        public override void Update(GameTime gameTime, EventManager events)
        {
            base.Update(gameTime, events);

              #region GamePad

              // GamePad
              P1LastGamePadState = P1GamePadState;
              P1GamePadState = GamePad.GetState(PlayerIndex.One);

              bool left = P1GamePadState.ThumbSticks.Left.X < 0.0f;
              bool right = P1GamePadState.ThumbSticks.Left.X > 0.0f;
              bool jump = (P1GamePadState.Buttons.A == ButtonState.Pressed
            && P1LastGamePadState.Buttons.A == ButtonState.Released);
              bool action = (P1GamePadState.Buttons.B == ButtonState.Released
            && P1LastGamePadState.Buttons.B == ButtonState.Pressed);

              #endregion

              #region Keyboard

              bool keyJump = (keyboard.IsKeyDown(Keys.Up)
            && lastKeyboard.IsKeyUp(Keys.Up));
              bool keyDownLeft = keyboard.IsKeyDown(Keys.Left);
              bool keyDownRight = keyboard.IsKeyDown(Keys.Right);
              bool keyAction = keyboard.IsKeyUp(Keys.Space)
            && lastKeyboard.IsKeyDown(Keys.Space);

              #endregion

              if (action || keyAction) events.Notify(Event.Action, null);
        }
Exemple #25
0
        //
        // Horizontal Movement
        protected void CheckHorizontalMovementKeys(KeyboardState ksKeys,
                                           GamePadState gsPad)
        {
            bool bResetTimer = false;

            player.Thrusting = false;
            if ((ksKeys.IsKeyDown(Keys.Right)) || (gsPad.ThumbSticks.Left.X > 0))
            {
                if (player.ScrollRate < iMaxHorizontalSpeed)
                {
                    player.ScrollRate += player.AccelerationRate;
                    if (player.ScrollRate > iMaxHorizontalSpeed)
                        player.ScrollRate = iMaxHorizontalSpeed;
                    bResetTimer = true;
                }
                player.Thrusting = true;
                player.Facing = 0;
            }

            if ((ksKeys.IsKeyDown(Keys.Left)) || (gsPad.ThumbSticks.Left.X < 0))
            {
                if (player.ScrollRate > -iMaxHorizontalSpeed)
                {
                    player.ScrollRate -= player.AccelerationRate;
                    if (player.ScrollRate < -iMaxHorizontalSpeed)
                        player.ScrollRate = -iMaxHorizontalSpeed;
                    bResetTimer = true;
                }
                player.Thrusting = true;
                player.Facing = 1;
            }

            if (bResetTimer)
                player.SpeedChangeCount = 0.0f;
        }
Exemple #26
0
        public override void Update(float deltaTime)
        {
            if (id == World.gameId)
            {
                gamePad = GamePad.GetState(PlayerIndex.One);
                keyboard = Keyboard.GetState();

                if (gamePad.Buttons.Y == ButtonState.Pressed &&
                    oldGamePad.Buttons.Y == ButtonState.Released &&
                    World.inMenu == false ||
                    keyboard.IsKeyDown(Keys.Tab) &&
                    oldKeyboard.IsKeyUp(Keys.Tab) &&
                    World.inMenu == false)
                {
                    World.inMenu = true;
                    World.menuManager.SwitchMenu(World.menuManager.shop);
                }
                else if (keyboard.IsKeyDown(Keys.Tab) &&
                   oldKeyboard.IsKeyUp(Keys.Tab) &&
                   World.inMenu == true)
                {
                    World.menuManager.CurrentMenu.BackOut();
                }
            }
            oldGamePad = gamePad;
            oldKeyboard = keyboard;
            base.Update(deltaTime);
        }
Exemple #27
0
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the object.
        /// </summary>
        //=========================================================================================
        public Gui_Game_Paused()
        {
            // Save the current kb and gamepad state;

            m_last_gamepad_state    = GamePad.GetState(PlayerIndex.One);
            m_last_keyboard_state   = Keyboard.GetState();
        }
 /// <summary>
 /// Performs the logic to control the Player.
 /// </summary>
 /// <param name="pad">The state of the gamepad used to control this player.</param>
 public void Update(GamePadState pad)
 {
     if (pad.ThumbSticks.Left.X >= 0.5) pos.X += speed;
     if (pad.ThumbSticks.Left.X <= -0.5) pos.X -= speed;
     if (pad.ThumbSticks.Left.Y >= 0.5) pos.Y -= speed;
     if (pad.ThumbSticks.Left.Y <= -0.5) pos.Y += speed;
 }
Exemple #29
0
 public void Update()
 {
     kbo = kb;
     gpo = gp;
     kb = Keyboard.GetState();
     this.gp = GamePad.GetState(PlayerIndex.One);
 }
Exemple #30
0
 public GetInput(PlayerIndex index)
 {
     playerIndex = index;
     directionBoolArray = new bool[4] { upPressed, leftPressed, downPressed, rightPressed };
     oldKeyState = Keyboard.GetState();
     oldPadState = GamePad.GetState(playerIndex);
 }
Exemple #31
0
 public Controls()
 {
     this.kb = Keyboard.GetState();
     this.kbo = Keyboard.GetState();
     this.gp = GamePad.GetState(PlayerIndex.One);
     this.gpo = GamePad.GetState(PlayerIndex.One);
 }
Exemple #32
0
        public void Update(Vector2 pos, MouseState mouse, GamePadState gps, GameTime gameTime)
        {
            //check user Drag Drop Events
            if (mouse.LeftButton == ButtonState.Pressed || gps.Buttons.A == ButtonState.Pressed)
            {
                //CHECK BUTTONS
                int clickedID = getClickedID(new Vector2(pos.X, pos.Y));
                if (clickedID >= 0)
                {
                    if (clickedID == 1)
                    {
                        main.stateManager.loadNextScreen(2, 0, gameTime);
                    }
                    if (clickedID == 2)
                    {
                        main.stateManager.loadNextScreen(4, 0, gameTime);
                    }
                    if (clickedID == 3)
                    {
                        main.lastState = 1;
                        main.stateManager.loadNextScreen(5, 0, gameTime);
                    }

                    Console.WriteLine("BUTTON PRESSED: clickedID: "+clickedID);
                    //APACURRO BOTONES
                }

            }
        }
Exemple #33
0
        /// <summary>
        ///   Constructs a new input state.
        /// </summary>
        public InputHelper(ScreenManager manager)
        {
            _currentKeyboardState = new KeyboardState();
            _currentGamePadState = new GamePadState();
            _currentMouseState = new MouseState();
            _currentVirtualState = new GamePadState();

            _lastKeyboardState = new KeyboardState();
            _lastGamePadState = new GamePadState();
            _lastMouseState = new MouseState();
            _lastVirtualState = new GamePadState();

            _manager = manager;

            _cursorIsVisible = false;
            _cursorMoved = false;
#if WINDOWS_PHONE
            _cursorIsValid = false;
#else
            _cursorIsValid = true;
#endif
            _cursor = Vector2.Zero;

            _handleVirtualStick = true;
        }
Exemple #34
0
 private void UpdateNormalButtons(XnaInput.GamePadState state)
 {
     UpdateButton(state.Buttons.A, GamePadButton.A);
     UpdateButton(state.Buttons.B, GamePadButton.B);
     UpdateButton(state.Buttons.X, GamePadButton.X);
     UpdateButton(state.Buttons.Y, GamePadButton.Y);
     UpdateButton(state.Buttons.Back, GamePadButton.Back);
     UpdateButton(state.Buttons.Start, GamePadButton.Start);
     UpdateButton(state.Buttons.BigButton, GamePadButton.BigButton);
 }
        internal bool Update(xinput.GamePadState curr)
        {
            if (_isConnected == curr.IsConnected)
            {
                return(false);
            }

            _isConnected = curr.IsConnected;

            return(true);
        }
        internal bool Update(DateTime timeStamp, xinput.GamePadState state)
        {
            if (_previous == state)
            {
                return(false);
            }

            _timeStamp = timeStamp;

            _previous = state;
            return(true);
        }
 public override void Update(GameTime gameTime)
 {
     lastState = st;
     st        = XnaInput.GamePad.GetState(index);
     if (cooldown > 0)
     {
         if (triggered)
         {
             try
             {
                 if (!vibrationFaild)
                 {
                     Controller.SetVibration(vibration);
                 }
             }
             catch (Exception)
             {
                 vibrationFaild = true;
             }
             triggered = false;
             vibrating = true;
         }
         cooldown -= gameTime.ElapsedGameTime.TotalMilliseconds;
         if (cooldown <= 0)
         {
             vibration.LeftMotorSpeed  = 0;
             vibration.RightMotorSpeed = 0;
             try
             {
                 if (!vibrationFaild)
                 {
                     Controller.SetVibration(vibration);
                 }
                 vibrating = false;
             }
             catch (Exception)
             {
                 vibrationFaild = true;
             }
         }
     }
 }
        public virtual IEnumerator <ITask> PollHandler(Poll poll)
        {
            DateTime timeStamp = DateTime.Now;

            xinput.GamePadState gamepad = _state.GetState();

            if (_state.Update(timeStamp, gamepad))
            {
                if (_state.Controller.Update(gamepad))
                {
                    SendNotification <ControllerChanged>(_submgr, _state.Controller);
                }

                if (_state.DPad.Update(timeStamp, gamepad.DPad))
                {
                    SendNotification <DPadChanged>(_submgr, _state.DPad);
                }

                if (_state.Buttons.Update(timeStamp, gamepad.Buttons))
                {
                    SendNotification <ButtonsChanged>(_submgr, _state.Buttons);
                }

                if (_state.Triggers.Update(timeStamp, gamepad.Triggers))
                {
                    SendNotification <TriggersChanged>(_submgr, _state.Triggers);
                }

                if (_state.Thumbsticks.Update(timeStamp, gamepad.ThumbSticks))
                {
                    SendNotification <ThumbsticksChanged>(_submgr, _state.Thumbsticks);
                }
            }

            poll.ResponsePort.Post(DefaultSubmitResponseType.Instance);
            yield break;
        }
        private bool GetInternal(XnaInput.GamePadState st, Buttons btn)
        {
            switch (btn)
            {
            case Buttons.A: return(st.Buttons.A == XnaInput.ButtonState.Pressed);

            case Buttons.B: return(st.Buttons.B == XnaInput.ButtonState.Pressed);

            case Buttons.X: return(st.Buttons.X == XnaInput.ButtonState.Pressed);

            case Buttons.Y: return(st.Buttons.Y == XnaInput.ButtonState.Pressed);

            case Buttons.R: return(st.Buttons.RightShoulder == XnaInput.ButtonState.Pressed);

            case Buttons.L: return(st.Buttons.LeftShoulder == XnaInput.ButtonState.Pressed);

            case Buttons.LeftStick: return(st.Buttons.LeftStick == XnaInput.ButtonState.Pressed);

            case Buttons.RightStick: return(st.Buttons.RightStick == XnaInput.ButtonState.Pressed);

            case Buttons.DPad_Left: return(st.DPad.Left == XnaInput.ButtonState.Pressed);

            case Buttons.DPad_Right: return(st.DPad.Right == XnaInput.ButtonState.Pressed);

            case Buttons.DPad_Up: return(st.DPad.Up == XnaInput.ButtonState.Pressed);

            case Buttons.DPad_Down: return(st.DPad.Down == XnaInput.ButtonState.Pressed);

            case Buttons.Select: return(st.Buttons.Back == XnaInput.ButtonState.Pressed);

            case Buttons.Start: return(st.Buttons.Start == XnaInput.ButtonState.Pressed);

            case Buttons.ToggleFullscreen: return(st.Buttons.Back == XnaInput.ButtonState.Pressed);
            }
            return(false);
        }
Exemple #40
0
        private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDeadZoneMode, GamePadDeadZone rightDeadZoneMode)
        {
            // If the device was disconneced then wait for
            // the timeout to elapsed before we test it again.
            if (!_connected[index] && !HasDisconnectedTimeoutElapsed(index))
            {
                return(GetDefaultState());
            }

            int packetNumber = 0;

            // Try to get the controller state.
            var gamepad = new SharpDX.XInput.Gamepad();

            try
            {
                SharpDX.XInput.State xistate;
                var controller = _controllers[index];
                _connected[index] = controller.GetState(out xistate);
                packetNumber      = xistate.PacketNumber;
                gamepad           = xistate.Gamepad;
            }
            catch (Exception)
            {
            }

            // If the device is disconnected retry it after the
            // timeout period has elapsed to avoid the overhead.
            if (!_connected[index])
            {
                SetDisconnectedTimeout(index);
                return(GetDefaultState());
            }

            var thumbSticks = new GamePadThumbSticks(
                leftPosition: new Vector2(gamepad.LeftThumbX, gamepad.LeftThumbY) / (float)short.MaxValue,
                rightPosition: new Vector2(gamepad.RightThumbX, gamepad.RightThumbY) / (float)short.MaxValue,
                leftDeadZoneMode: leftDeadZoneMode,
                rightDeadZoneMode: rightDeadZoneMode);

            var triggers = new GamePadTriggers(
                leftTrigger: gamepad.LeftTrigger / (float)byte.MaxValue,
                rightTrigger: gamepad.RightTrigger / (float)byte.MaxValue);

            var dpadState = new GamePadDPad(
                upValue: ConvertToButtonState(gamepad.Buttons, SharpDX.XInput.GamepadButtonFlags.DPadUp),
                downValue: ConvertToButtonState(gamepad.Buttons, SharpDX.XInput.GamepadButtonFlags.DPadDown),
                leftValue: ConvertToButtonState(gamepad.Buttons, SharpDX.XInput.GamepadButtonFlags.DPadLeft),
                rightValue: ConvertToButtonState(gamepad.Buttons, SharpDX.XInput.GamepadButtonFlags.DPadRight));

            var buttons = ConvertToButtons(
                buttonFlags: gamepad.Buttons,
                leftTrigger: gamepad.LeftTrigger,
                rightTrigger: gamepad.RightTrigger);

            var state = new GamePadState(
                thumbSticks: thumbSticks,
                triggers: triggers,
                buttons: buttons,
                dPad: dpadState);

            state.PacketNumber = packetNumber;

            return(state);
        }
Exemple #41
0
        private static GamePadState PlatformGetState(int index, GamePadDeadZone deadZoneMode)
        {
            var ind = (GCControllerPlayerIndex)index;


            var         buttons   = new List <Buttons>();
            bool        connected = false;
            ButtonState Up        = ButtonState.Released;
            ButtonState Down      = ButtonState.Released;
            ButtonState Left      = ButtonState.Released;
            ButtonState Right     = ButtonState.Released;

            Vector2 leftThumbStickPosition  = Vector2.Zero;
            Vector2 rightThumbStickPosition = Vector2.Zero;

            float leftTriggerValue  = 0;
            float rightTriggerValue = 0;

            AssingIndex(ind);

            foreach (var controller in GCController.Controllers)
            {
                if (controller == null)
                {
                    continue;
                }

                if (controller.PlayerIndex != (int)ind)
                {
                    continue;
                }

                connected = true;

                if (controller.ExtendedGamepad != null)
                {
                    if (controller.ExtendedGamepad.ButtonA.IsPressed == true && !buttons.Contains(Buttons.A))
                    {
                        buttons.Add(Buttons.A);
                    }
                    if (controller.ExtendedGamepad.ButtonB.IsPressed == true && !buttons.Contains(Buttons.B))
                    {
                        buttons.Add(Buttons.B);
                    }
                    if (controller.ExtendedGamepad.ButtonX.IsPressed == true && !buttons.Contains(Buttons.X))
                    {
                        buttons.Add(Buttons.X);
                    }
                    if (controller.ExtendedGamepad.ButtonY.IsPressed == true && !buttons.Contains(Buttons.Y))
                    {
                        buttons.Add(Buttons.Y);
                    }

                    if (controller.ExtendedGamepad.LeftShoulder.IsPressed == true && !buttons.Contains(Buttons.LeftShoulder))
                    {
                        buttons.Add(Buttons.LeftShoulder);
                    }
                    if (controller.ExtendedGamepad.RightShoulder.IsPressed == true && !buttons.Contains(Buttons.RightShoulder))
                    {
                        buttons.Add(Buttons.RightShoulder);
                    }

                    Up    = controller.ExtendedGamepad.DPad.Up.IsPressed ? ButtonState.Pressed : ButtonState.Released;
                    Down  = controller.ExtendedGamepad.DPad.Down.IsPressed ? ButtonState.Pressed : ButtonState.Released;
                    Left  = controller.ExtendedGamepad.DPad.Left.IsPressed ? ButtonState.Pressed : ButtonState.Released;
                    Right = controller.ExtendedGamepad.DPad.Right.IsPressed ? ButtonState.Pressed : ButtonState.Released;

                    leftThumbStickPosition.X = controller.ExtendedGamepad.LeftThumbstick.XAxis.Value;
                    leftThumbStickPosition.Y = controller.ExtendedGamepad.LeftThumbstick.YAxis.Value;

                    rightThumbStickPosition.X = controller.ExtendedGamepad.RightThumbstick.XAxis.Value;
                    rightThumbStickPosition.Y = controller.ExtendedGamepad.RightThumbstick.YAxis.Value;

                    leftTriggerValue  = controller.ExtendedGamepad.LeftTrigger.Value;
                    rightTriggerValue = controller.ExtendedGamepad.RightTrigger.Value;
                }
                else if (controller.Gamepad != null)
                {
                    if (controller.Gamepad.ButtonA.IsPressed == true && !buttons.Contains(Buttons.A))
                    {
                        buttons.Add(Buttons.A);
                    }
                    if (controller.Gamepad.ButtonB.IsPressed == true && !buttons.Contains(Buttons.B))
                    {
                        buttons.Add(Buttons.B);
                    }
                    if (controller.Gamepad.ButtonX.IsPressed == true && !buttons.Contains(Buttons.X))
                    {
                        buttons.Add(Buttons.X);
                    }
                    if (controller.Gamepad.ButtonY.IsPressed == true && !buttons.Contains(Buttons.Y))
                    {
                        buttons.Add(Buttons.Y);
                    }
                    Up    = controller.Gamepad.DPad.Up.IsPressed ? ButtonState.Pressed : ButtonState.Released;
                    Down  = controller.Gamepad.DPad.Down.IsPressed ? ButtonState.Pressed : ButtonState.Released;
                    Left  = controller.Gamepad.DPad.Left.IsPressed ? ButtonState.Pressed : ButtonState.Released;
                    Right = controller.Gamepad.DPad.Right.IsPressed ? ButtonState.Pressed : ButtonState.Released;
                }
            }
            var state = new GamePadState(
                new GamePadThumbSticks(leftThumbStickPosition, rightThumbStickPosition),
                new GamePadTriggers(leftTriggerValue, rightTriggerValue),
                new GamePadButtons(buttons.ToArray()),
                new GamePadDPad(Up, Down, Left, Right));

            state.IsConnected = connected;
            return(state);
        }
Exemple #42
0
 private void UpdateAllButtons(XnaInput.GamePadState state)
 {
     UpdateNormalButtons(state);
     UpdateStickAndShoulderButtons(state);
     UpdateDPadButtons(state);
 }
Exemple #43
0
        public static GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode)
        {
            IntPtr device = INTERNAL_devices[(int)playerIndex];

            if (device == IntPtr.Zero)
            {
                return(InitializedState);
            }

            // Do not attempt to understand this number at all costs!
            const float DeadZoneSize = 0.27f;

            // SDL_GameController
            if (INTERNAL_isGameController[(int)playerIndex])
            {
                // The "master" button state is built from this.
                Buttons gc_buttonState = (Buttons)0;

                // Sticks
                GamePadThumbSticks gc_sticks = new GamePadThumbSticks(
                    new Vector2(
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX
                            ) / 32768.0f,
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY
                            ) / -32768.0f
                        ),
                    new Vector2(
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX
                            ) / 32768.0f,
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY
                            ) / -32768.0f
                        )
                    );
                gc_sticks.ApplyDeadZone(deadZoneMode, DeadZoneSize);
                gc_buttonState |= READ_StickToButtons(
                    gc_sticks.Left,
                    Buttons.LeftThumbstickLeft,
                    Buttons.LeftThumbstickRight,
                    Buttons.LeftThumbstickUp,
                    Buttons.LeftThumbstickDown,
                    DeadZoneSize
                    );
                gc_buttonState |= READ_StickToButtons(
                    gc_sticks.Right,
                    Buttons.RightThumbstickLeft,
                    Buttons.RightThumbstickRight,
                    Buttons.RightThumbstickUp,
                    Buttons.RightThumbstickDown,
                    DeadZoneSize
                    );

                // Triggers
                GamePadTriggers gc_triggers = new GamePadTriggers(
                    (float)SDL.SDL_GameControllerGetAxis(
                        device,
                        SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT
                        ) / 32768.0f,
                    (float)SDL.SDL_GameControllerGetAxis(
                        device,
                        SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT
                        ) / 32768.0f
                    );
                gc_buttonState |= READ_TriggerToButton(
                    gc_triggers.Left,
                    Buttons.LeftTrigger,
                    DeadZoneSize
                    );
                gc_buttonState |= READ_TriggerToButton(
                    gc_triggers.Right,
                    Buttons.RightTrigger,
                    DeadZoneSize
                    );

                // Buttons
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A) != 0)
                {
                    gc_buttonState |= Buttons.A;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B) != 0)
                {
                    gc_buttonState |= Buttons.B;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X) != 0)
                {
                    gc_buttonState |= Buttons.X;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y) != 0)
                {
                    gc_buttonState |= Buttons.Y;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK) != 0)
                {
                    gc_buttonState |= Buttons.Back;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE) != 0)
                {
                    gc_buttonState |= Buttons.BigButton;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START) != 0)
                {
                    gc_buttonState |= Buttons.Start;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK) != 0)
                {
                    gc_buttonState |= Buttons.LeftStick;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK) != 0)
                {
                    gc_buttonState |= Buttons.RightStick;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER) != 0)
                {
                    gc_buttonState |= Buttons.LeftShoulder;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) != 0)
                {
                    gc_buttonState |= Buttons.RightShoulder;
                }

                // DPad
                GamePadDPad gc_dpad;
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP) != 0)
                {
                    gc_buttonState |= Buttons.DPadUp;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN) != 0)
                {
                    gc_buttonState |= Buttons.DPadDown;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT) != 0)
                {
                    gc_buttonState |= Buttons.DPadLeft;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT) != 0)
                {
                    gc_buttonState |= Buttons.DPadRight;
                }
                gc_dpad = new GamePadDPad(gc_buttonState);

                // Compile the master buttonstate
                GamePadButtons gc_buttons = new GamePadButtons(gc_buttonState);

                // Build the GamePadState, increment PacketNumber if state changed.
                GamePadState gc_builtState = new GamePadState(
                    gc_sticks,
                    gc_triggers,
                    gc_buttons,
                    gc_dpad
                    );
                gc_builtState.PacketNumber = INTERNAL_states[(int)playerIndex].PacketNumber;
                if (gc_builtState != INTERNAL_states[(int)playerIndex])
                {
                    gc_builtState.PacketNumber       += 1;
                    INTERNAL_states[(int)playerIndex] = gc_builtState;
                }

                return(gc_builtState);
            }

            // SDL_Joystick

            // We will interpret the joystick values into this.
            Buttons buttonState = (Buttons)0;

            // Sticks
            GamePadThumbSticks sticks = new GamePadThumbSticks(
                new Vector2(
                    READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_LX, device),
                    -READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_LY, device)
                    ),
                new Vector2(
                    READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_RX, device),
                    -READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_RY, device)
                    )
                );

            sticks.ApplyDeadZone(deadZoneMode, DeadZoneSize);
            buttonState |= READ_StickToButtons(
                sticks.Left,
                Buttons.LeftThumbstickLeft,
                Buttons.LeftThumbstickRight,
                Buttons.LeftThumbstickUp,
                Buttons.LeftThumbstickDown,
                DeadZoneSize
                );
            buttonState |= READ_StickToButtons(
                sticks.Right,
                Buttons.RightThumbstickLeft,
                Buttons.RightThumbstickRight,
                Buttons.RightThumbstickUp,
                Buttons.RightThumbstickDown,
                DeadZoneSize
                );

            // Buttons
            buttonState = READ_ReadButtons(device, DeadZoneSize);

            // Triggers
            GamePadTriggers triggers = new GamePadTriggers(
                READTYPE_ReadFloat(INTERNAL_joystickConfig.TRIGGER_LT, device),
                READTYPE_ReadFloat(INTERNAL_joystickConfig.TRIGGER_RT, device)
                );

            buttonState |= READ_TriggerToButton(
                triggers.Left,
                Buttons.LeftTrigger,
                DeadZoneSize
                );
            buttonState |= READ_TriggerToButton(
                triggers.Right,
                Buttons.RightTrigger,
                DeadZoneSize
                );

            // Compile the GamePadButtons with our Buttons state
            GamePadButtons buttons = new GamePadButtons(buttonState);

            // DPad
            GamePadDPad dpad = new GamePadDPad(buttons.buttons);

            // Build the GamePadState, increment PacketNumber if state changed.
            GamePadState builtState = new GamePadState(
                sticks,
                triggers,
                buttons,
                dpad
                );

            builtState.PacketNumber = INTERNAL_states[(int)playerIndex].PacketNumber;
            if (builtState != INTERNAL_states[(int)playerIndex])
            {
                builtState.PacketNumber          += 1;
                INTERNAL_states[(int)playerIndex] = builtState;
            }

            return(builtState);
        }
Exemple #44
0
        private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDeadZoneMode, GamePadDeadZone rightDeadZoneMode)
        {
            var ind = (GCControllerPlayerIndex)index;


            Buttons     buttons   = 0;
            bool        connected = false;
            ButtonState Up        = ButtonState.Released;
            ButtonState Down      = ButtonState.Released;
            ButtonState Left      = ButtonState.Released;
            ButtonState Right     = ButtonState.Released;

            Vector2 leftThumbStickPosition  = Vector2.Zero;
            Vector2 rightThumbStickPosition = Vector2.Zero;

            float leftTriggerValue  = 0;
            float rightTriggerValue = 0;

            AssingIndex(ind);

            foreach (var controller in GCController.Controllers)
            {
                if (controller == null)
                {
                    continue;
                }

                if (controller.PlayerIndex != (int)ind)
                {
                    continue;
                }

                connected = true;

                if (controller.ExtendedGamepad != null)
                {
                    if (controller.ExtendedGamepad.ButtonA.IsPressed)
                    {
                        buttons |= Buttons.A;
                    }
                    if (controller.ExtendedGamepad.ButtonB.IsPressed)
                    {
                        buttons |= Buttons.B;
                    }
                    if (controller.ExtendedGamepad.ButtonX.IsPressed)
                    {
                        buttons |= Buttons.X;
                    }
                    if (controller.ExtendedGamepad.ButtonY.IsPressed)
                    {
                        buttons |= Buttons.Y;
                    }

                    if (controller.ExtendedGamepad.LeftShoulder.IsPressed)
                    {
                        buttons |= Buttons.LeftShoulder;
                    }
                    if (controller.ExtendedGamepad.RightShoulder.IsPressed)
                    {
                        buttons |= Buttons.RightShoulder;
                    }

                    if (controller.ExtendedGamepad.LeftTrigger.IsPressed)
                    {
                        buttons |= Buttons.LeftTrigger;
                    }
                    if (controller.ExtendedGamepad.RightTrigger.IsPressed)
                    {
                        buttons |= Buttons.RightTrigger;
                    }

                    if (controller.ExtendedGamepad.DPad.Up.IsPressed)
                    {
                        Up       = ButtonState.Pressed;
                        buttons |= Buttons.DPadUp;
                    }
                    if (controller.ExtendedGamepad.DPad.Down.IsPressed)
                    {
                        Down     = ButtonState.Pressed;
                        buttons |= Buttons.DPadDown;
                    }
                    if (controller.ExtendedGamepad.DPad.Left.IsPressed)
                    {
                        Left     = ButtonState.Pressed;
                        buttons |= Buttons.DPadLeft;
                    }
                    if (controller.ExtendedGamepad.DPad.Right.IsPressed)
                    {
                        Right    = ButtonState.Pressed;
                        buttons |= Buttons.DPadRight;
                    }

                    leftThumbStickPosition.X  = controller.ExtendedGamepad.LeftThumbstick.XAxis.Value;
                    leftThumbStickPosition.Y  = controller.ExtendedGamepad.LeftThumbstick.YAxis.Value;
                    rightThumbStickPosition.X = controller.ExtendedGamepad.RightThumbstick.XAxis.Value;
                    rightThumbStickPosition.Y = controller.ExtendedGamepad.RightThumbstick.YAxis.Value;
                    leftTriggerValue          = controller.ExtendedGamepad.LeftTrigger.Value;
                    rightTriggerValue         = controller.ExtendedGamepad.RightTrigger.Value;
                }
                else if (controller.Gamepad != null)
                {
                    if (controller.Gamepad.ButtonA.IsPressed)
                    {
                        buttons |= Buttons.A;
                    }
                    if (controller.Gamepad.ButtonB.IsPressed)
                    {
                        buttons |= Buttons.B;
                    }
                    if (controller.Gamepad.ButtonX.IsPressed)
                    {
                        buttons |= Buttons.X;
                    }
                    if (controller.Gamepad.ButtonY.IsPressed)
                    {
                        buttons |= Buttons.Y;
                    }

                    if (controller.Gamepad.DPad.Up.IsPressed)
                    {
                        Up       = ButtonState.Pressed;
                        buttons |= Buttons.DPadUp;
                    }
                    if (controller.Gamepad.DPad.Down.IsPressed)
                    {
                        Down     = ButtonState.Pressed;
                        buttons |= Buttons.DPadDown;
                    }
                    if (controller.Gamepad.DPad.Left.IsPressed)
                    {
                        Left     = ButtonState.Pressed;
                        buttons |= Buttons.DPadLeft;
                    }
                    if (controller.Gamepad.DPad.Right.IsPressed)
                    {
                        Right    = ButtonState.Pressed;
                        buttons |= Buttons.DPadRight;
                    }
                }
            }
            var state = new GamePadState(
                new GamePadThumbSticks(leftThumbStickPosition, rightThumbStickPosition, leftDeadZoneMode, rightDeadZoneMode),
                new GamePadTriggers(leftTriggerValue, rightTriggerValue),
                new GamePadButtons(buttons),
                new GamePadDPad(Up, Down, Left, Right));

            state.IsConnected = connected;
            return(state);
        }