IsButtonDown() public method

public IsButtonDown ( Buttons button ) : bool
button Buttons
return bool
Example #1
0
        public void Update(GamePadState pad)
        {
            if (pad.IsButtonDown(Buttons.LeftThumbstickDown) && !oldPad.IsButtonDown(Buttons.LeftThumbstickDown))
            {
                if (current < 3)
                {
                    current++;
                }
            }
            if (pad.IsButtonDown(Buttons.LeftThumbstickUp) && !oldPad.IsButtonDown(Buttons.LeftThumbstickUp))
            {
                if (current > 1)
                {
                    current--;
                }
            }
            if (pad.IsButtonDown(Buttons.A) && oldPad.IsButtonUp(Buttons.A))
            {
                if (current == 1)
                {
                    FirstGame.start = true;
                }
                else if (current == 3)
                {
                    FirstGame.exit = true;
                }
            }

            oldPad = pad;
        }
Example #2
0
        // 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");
            }
        }
        public void Update()
        {
            gamePadState = GamePad.GetState(PlayerIndex.One);
            bool foundInput = false;

            if (gamePadState.IsButtonDown(Buttons.Start) && !startPressed)
            {
                startPressed = true;
                new StartButtonCommand().Execute();
            }
            else if (gamePadState.IsButtonUp(Buttons.Start) && startPressed)
            {
                startPressed = false;
            }

            if (playableObject.IsEnteringPipe || playableObject.IsExitingPipe)
            {
                new MarioNoInputCommand(playableObject).Execute();
            }
            else
            {
                if (gamePadState.IsButtonDown(Buttons.A) && !jumpPressed)
                {
                    jumpPressed = true;
                    new MarioJumpCommand(playableObject).Execute();
                    foundInput = true;
                }
                else if (gamePadState.IsButtonDown(Buttons.A))
                {
                    foundInput = true;
                }
                else if (gamePadState.IsButtonUp(Buttons.A) && jumpPressed)
                {
                    jumpPressed = false;
                }

                if (gamePadState.IsButtonDown(Buttons.B))
                {
                    playableObject.MaxHorizontalVelocity = GameValues.MarioRunningSpeed;
                    new MarioRunCommand(playableObject).Execute();
                }
                else
                {
                    playableObject.MaxHorizontalVelocity = GameValues.MarioWalkingSpeed;
                }

                foreach (KeyValuePair<Buttons, ICommand> item in buttonMap)
                {
                    if (gamePadState.IsButtonDown(item.Key))
                    {
                        item.Value.Execute();
                        foundInput = true;
                    }
                }
                if (!foundInput)
                {
                    new MarioNoInputCommand(playableObject).Execute();
                }
            }
        }
Example #4
0
        public static void updateSingleplayer()
        {
            prevGamepad = currGamepad;
            currGamepad = GamePad.GetState(PlayerIndex.One);

            Vector2 moveVec = new Vector2(0, 0);

            if (currGamepad.IsButtonDown(Buttons.DPadUp)) moveVec += new Vector2(0, -speed);
            if (currGamepad.IsButtonDown(Buttons.DPadLeft)) moveVec += new Vector2(-speed, 0);
            if (currGamepad.IsButtonDown(Buttons.DPadDown)) moveVec += new Vector2(0, speed);
            if (currGamepad.IsButtonDown(Buttons.DPadRight)) moveVec += new Vector2(speed, 0);

            if (isClicked(Buttons.A) && !isJumping) isJumping = true;

            if (isJumping && !limitReached)
            {
                moveVec += new Vector2(0, -speed);
                test += speed;
                if (test == limit)
                    limitReached = true;
            }
            else if (limitReached)
            {
                moveVec -= new Vector2(0, -speed);
                test -= speed;
                if (test == 0)
                {
                    limitReached = false;
                    isJumping = false;
                }
            }
            Camera2D.movePosition(moveVec);
        }
        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))
            {

            }
        }
 public static void FireCannons(GamePadState gs, GamePadState previousGamePadState, Player player, GameTime gameTime)
 {
     if (gs.IsButtonDown(actionKeys[Action.FireLeftCannon]))
     {
         player.FireLeftCannons(gameTime);
     }
     if (gs.IsButtonDown(actionKeys[Action.FireRightCannon]))
     {
         player.FireRightCannons(gameTime);
     }
 }
Example #7
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;
        }
        /// <summary>
        /// Generates a GamePadState based on the touch input provided (as applied to the on screen controls) and the gamepad state
        /// </summary>
        public GamePadState GetState(TouchCollection touchState, GamePadState gpState)
        {
            //Work out what buttons are pressed based on the touchState
            Buttons buttonsPressed = 0;

            foreach (TouchLocation touch in touchState)
            {
                if (touch.State == TouchLocationState.Moved || touch.State == TouchLocationState.Pressed)
                {
                    //Scale the touch position to be in _baseScreenSize coordinates
                    Vector2 pos = touch.Position;
                    Vector2.Transform(ref pos, ref globalTransformation, out pos);

                    if (pos.X < 128)
                        buttonsPressed |= Buttons.DPadLeft;
                    else if (pos.X < 256)
                        buttonsPressed |= Buttons.DPadRight;
                    else if (pos.X >= baseScreenSize.X - 128)
                        buttonsPressed |= Buttons.A;
                }
            }

            //Combine the buttons of the real gamepad
            GamePadButtons gpButtons = gpState.Buttons;
            buttonsPressed |= (gpButtons.A == ButtonState.Pressed ? Buttons.A : 0);
            buttonsPressed |= (gpButtons.B == ButtonState.Pressed ? Buttons.B : 0);
            buttonsPressed |= (gpButtons.X == ButtonState.Pressed ? Buttons.X : 0);
            buttonsPressed |= (gpButtons.Y == ButtonState.Pressed ? Buttons.Y : 0);

            buttonsPressed |= (gpButtons.Start == ButtonState.Pressed ? Buttons.Start : 0);
            buttonsPressed |= (gpButtons.Back == ButtonState.Pressed ? Buttons.Back : 0);

            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadDown) ? Buttons.DPadDown : 0;
            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadLeft) ? Buttons.DPadLeft : 0;
            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadRight) ? Buttons.DPadRight : 0;
            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadUp) ? Buttons.DPadUp : 0;

            buttonsPressed |= (gpButtons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0);
            buttonsPressed |= (gpButtons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0);
            buttonsPressed |= (gpButtons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0);

            buttonsPressed |= (gpButtons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0);
            buttonsPressed |= (gpButtons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0);

            var buttons = new GamePadButtons(buttonsPressed);

            return new GamePadState(gpState.ThumbSticks, gpState.Triggers, buttons, gpState.DPad);
        }
Example #9
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            _keyState = Keyboard.GetState();
            _padState = GamePad.GetState(PlayerIndex.One);

            //Let the Scene Manager do it's thing

            if ((_prevKeyState.IsKeyDown(Keys.P) && !_keyState.IsKeyDown(Keys.P)) || (_prevPadState.IsButtonDown(Buttons.Y) && !_padState.IsButtonDown(Buttons.Y)))
            {
                // The 'P' key has just been released
                // This will only fire ONCE when the 'P' key is released
                if (_pauseOn)
                    _pauseOn = false;
                else
                    _pauseOn = true;
            }

            if(!_pauseOn)
                _manager.NextScene().Update(gameTime);

            //Console.WriteLine();
            _prevKeyState = _keyState;
            _prevPadState = _padState;

            base.Update(gameTime);
        }
Example #10
0
        /// <summary>
        /// Call this method when input is received to have the console react to the user's commands.
        /// </summary>
        /// <param name="kbs">The current keyboard state.</param>
        /// <returns>The Command that corresponds to the user's input.</returns>
        public void CheckInput(GamePadState gs)
        {
            if (_menuActive)
            {
                if (gs.IsButtonDown(Buttons.Y) && _oldPad.IsButtonUp(Buttons.Y))
                    _menuActive = false;
            }
            else
            {
                // Should we bring the menu up?
                if (gs.IsButtonDown(Buttons.Y) && _oldPad.IsButtonUp(Buttons.Y))
                    _menuActive = true;
            }

            _oldPad = gs;
        }
Example #11
0
 public override void Update( TimeSpan gameTime, KeyboardState keyState, MouseState mouseState, GamePadState padState )
 {
     if ( keyState.IsKeyDown( Keys.Space ) || padState.IsButtonDown( Buttons.X ) || keyState.IsKeyDown( Keys.X ) )
     {
         ReferMenu( null );
     }
 }
Example #12
0
        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;
        }
Example #13
0
        public void InputsPlayer(GameTime gameTime, bool move, bool jump, Player player)
        {
            // Save previous keyboard/gamepad states
            previousKeyboardState = currentKeyboardState;
            previousGamepadState = currentGamepadState;

            // Read current keyboard/gamepad
            currentKeyboardState = Keyboard.GetState();
            currentGamepadState = GamePad.GetState(PlayerIndex.One);

            if (move && player.CanMove)
            {
                if (currentKeyboardState.IsKeyDown(Keys.Left) || currentGamepadState.ThumbSticks.Left.X < 0)
                    player.Move(-1f);
                else if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamepadState.ThumbSticks.Left.X > 0)
                    player.Move(1f);
                else
                    player.Move(0f);
            }

            if (player.CanJump && jump)
            {
                if (currentGamepadState.IsButtonDown(Buttons.A) && previousGamepadState.IsButtonUp(Buttons.A))
                    player.Jump();
                else if (currentKeyboardState.IsKeyDown(Keys.Z) && previousKeyboardState.IsKeyUp(Keys.Z))
                    player.Jump();
            }

            if (player.IsOverDoor)
            {
                if (currentGamepadState.ThumbSticks.Left.Y < 0
                    && previousGamepadState.ThumbSticks.Left.Y < 0
                    && player.Velocity.X == 0
                    )
                    player.EnterDoor();
                else if (currentKeyboardState.IsKeyDown(Keys.Up)
                    && previousKeyboardState.IsKeyUp(Keys.Up)
                    && player.Velocity.X == 0
                    )
                    player.EnterDoor();
            }

            if (currentGamepadState.IsButtonDown(Buttons.B) && previousGamepadState.IsButtonUp(Buttons.B))
                player.Attack(gameTime);
            else if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
                player.Attack(gameTime);
        }
 public static void PickupGold(GamePadState gs, GamePadState previousGamePadState, Player player, GameTime gameTime)
 {
     var pickupGoldButton = actionKeys[Action.PickupGold];
     if (gs.IsButtonDown(pickupGoldButton) && previousGamePadState.IsButtonUp(pickupGoldButton))
     {
         player.AttemptPickupGold();
     }
 }
Example #15
0
        public void Update()
        {
            motion = Vector2.Zero;

            keyboardState = Keyboard.GetState();
            gamePadState = GamePad.GetState(PlayerIndex.One);

            if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.IsButtonDown(Buttons.LeftThumbstickLeft))
                motion.X = -1;

            if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.IsButtonDown(Buttons.LeftThumbstickRight))
                motion.X = 1;

            motion.X *= paddleSpeed;
            position += motion;
            checkInBounds();
        }
Example #16
0
 public void Update(GamePadState pad)
 {
     if (pad.IsButtonDown(Buttons.A) && oldPad.IsButtonUp(Buttons.A))
     {
         FirstGame.end = false;
         FirstGame.reload = true;
     }
     oldPad = pad;
 }
Example #17
0
 public void Update(GamePadState gs, GameTime gt)
 {
     prev = now;
     now = gs.IsButtonDown(btn);
     if(now) {
         pressed += gt.ElapsedGameTime;
     } else {
         pressed = new TimeSpan(0);
     }
 }
Example #18
0
        /// <summary>
        /// Static function that manages and updates everything that envolves the controller's buttons
        /// </summary>
        /// <param name="xboxState">The current state of the Xbox controller</param>
        /// <param name="mouseState">The current state of the mouse</param>
        public static void Process(GamePadState xboxState, MouseState mouseState)
        {
            //Check for exit
            if (xboxState.IsButtonDown(ApplicationData.exitProcess.Value))
                Environment.Exit(0);

            //Update each button on the buttons list
            foreach (IXboxButton btn in ApplicationData.xboxButtons)
                btn.Update(xboxState, mouseState);
        }
Example #19
0
 public void GetPressedButtons(GamePadState gamePadState)
 {
     foreach (Buttons button in Enum.GetValues(typeof(Buttons)))
     {
         if (gamePadState.IsButtonDown(button))
         {
             pressedButtons.Add(button);
         }
     }
 }
Example #20
0
 internal void Update(KeyboardState kbState, GamePadState gpState)
 {
     previousStatus = currentStatus;
     currentStatus = false;
     foreach (Keys k in keyList)
         if (kbState.IsKeyDown(k))
             currentStatus = true;
     foreach (Buttons b in buttonList)
         if (gpState.IsButtonDown(b))
             currentStatus = true;
 }
        public static GamePadChangeSet getGamePadStateChange(GamePadState newState, GamePadState oldState)
        {
            GamePadChangeSet gamePadStateChanges;
            gamePadStateChanges.buttonChanges = new List<ButtonChange>();

            foreach (Buttons but in Enum.GetValues(typeof(Buttons)))
            {
                if (newState.IsButtonDown(but) != oldState.IsButtonDown(but))
                    gamePadStateChanges.buttonChanges.Add(
                        new ButtonChange()
                        { button = but,
                          state = newState.IsButtonDown(but) ?
                            ButtonState.Pressed :
                            ButtonState.Released
                        }
                    );
            }

            return gamePadStateChanges;
        }
Example #22
0
        public void ConstructDPadState(Buttons button, ButtonState[] expectedDPadButtonStates)
        {
            var state = new GamePadState(Vector2.Zero, Vector2.Zero, 0f, 0f, button != 0 ? new Buttons[] { button } : new Buttons[] { });

            if (button != 0)
                Assert.True(state.IsButtonDown(button));

            Assert.AreEqual(expectedDPadButtonStates[0], state.DPad.Down, "DPad.Down Pressed or Released");
            Assert.AreEqual(expectedDPadButtonStates[1], state.DPad.Left, "DPad.Left Pressed or Released");
            Assert.AreEqual(expectedDPadButtonStates[2], state.DPad.Right, "DPad.Right Pressed or Released");
            Assert.AreEqual(expectedDPadButtonStates[3], state.DPad.Up, "DPad.Up Pressed or Released");
        }
Example #23
0
        /// <summary>
        /// Esta função reconhece a direção atual do controle a parti do estado do GamePad ou do teclado.
        /// Ela retorna um Button que pode ser comparado com as constantes dessa própria classe.
        /// </summary>
        /// <param name="gamePad">Estado do GamePad</param>
        /// <param name="keyboard">Estado do Teclado</param>
        /// <param name="keyboardMap">Mapa do teclado</param>
        /// <returns></returns>
        public static Buttons FromInput(GamePadState gamePad, KeyboardState keyboard, Dictionary<GameKeys, Keys> keyboardMap)
        {
            Buttons direction = None;

            //Pega a direção vertical.
            if (gamePad.IsButtonDown(Buttons.DPadUp) ||
               gamePad.IsButtonDown(Buttons.LeftThumbstickUp) ||
                keyboard.IsKeyDown(keyboardMap[GameKeys.Up]))
            {
                direction |= Up;
            }
            else if(gamePad.IsButtonDown(Buttons.DPadDown) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickDown) ||
                keyboard.IsKeyDown(keyboardMap[GameKeys.Down]))
            {
                direction |= Down;
            }

            //Combina com a direção horizontal.

            if (gamePad.IsButtonDown(Buttons.DPadLeft) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickLeft) ||
                keyboard.IsKeyDown(keyboardMap[GameKeys.Left]))
            {
                direction |= Left;
            } else if(gamePad.IsButtonDown(Buttons.DPadRight) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickRight) ||
                keyboard.IsKeyDown(keyboardMap[GameKeys.Right]))
            {
                direction |= Right;
            }

            return direction;
        }
Example #24
0
 public bool Accelerar()
 {
     if (_tecladoSelect)
     {
         keyboard = Keyboard.GetState();
         return keyboard.IsKeyDown(Keys.W);
     }
     else
     {
         gamepad = GamePad.GetState(numplayer);
         return gamepad.IsButtonDown(Buttons.A);
     }
 }
Example #25
0
 public bool Abajo()
 {
     if (_tecladoSelect)
     {
         keyboard = Keyboard.GetState();
         return keyboard.IsKeyDown(Keys.S);
     }
     else
     {
         gamepad = GamePad.GetState(numplayer);
         return gamepad.IsButtonDown(Buttons.LeftThumbstickDown);
     }
 }
Example #26
0
        // Update & Draw
        public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState)
        {
            for (int i = 0; i < _btnNumber; i++)
                _buttons[i].Update(mouse, keyboard);

            if (keyboard.IsKeyDown(Keys.Down) || gamePadState.IsButtonDown(Buttons.DPadDown))
                DownButton();
            if (keyboard.IsKeyUp(Keys.Down) && gamePadState.IsButtonUp(Buttons.DPadDown))
                _currentDownState = false;

            if (keyboard.IsKeyDown(Keys.Up) || gamePadState.IsButtonDown(Buttons.DPadUp))
                UpButton();
            if (keyboard.IsKeyUp(Keys.Up) && gamePadState.IsButtonUp(Buttons.DPadUp))
                _currentUpState = false;

            if (keyboard.IsKeyDown(Keys.Enter) || gamePadState.Buttons.Start == ButtonState.Pressed || gamePadState.Buttons.A == ButtonState.Pressed)
            {
                switch (_selection)
                {
                    case 0:
                        {
                            Game1.gameState = GameState.Game;
                            break;
                        }

                    case 1:
                        {

                            break;
                        }

                    case 2:
                        {
                            exitGame = true;
                            break;
                        }
                }
            }
        }
        /// <summary>
        /// Updates the button and executes it's wanted action if necessary
        /// </summary>
        /// <param name="xboxState">The current state of the Xbox Controller</param>
        /// <param name="mouseState">The current state of the mouse</param>
        public void Update(GamePadState xboxState, MouseState mouseState)
        {
            //Update the special buttons
            if (ApplicationData.control.HasValue && button == ApplicationData.control.Value) { control = xboxState.IsButtonDown(button); return; }
            if (ApplicationData.shift.HasValue && button == ApplicationData.shift.Value) { shift = xboxState.IsButtonDown(button); return; }
            if (ApplicationData.alt.HasValue && button == ApplicationData.alt.Value) { alt = xboxState.IsButtonDown(button); return; }

            if (xboxState.IsButtonDown(button))
            {
                if (wasUp || (useTimer && timer.ElapsedMilliseconds > timerInterval))
                {
                    string addons = (control ? KeyboardButton.Control : "") + (shift ? KeyboardButton.Shift : "") + (alt ? KeyboardButton.Alt : "");

                    keyboard_event.SendWait(addons + keyboardButton);

                    wasUp = false;
                    if (useTimer) timer.Restart();
                }
            }
            else
                wasUp = true;
        }
Example #28
0
        private void GetInput(
            KeyboardState keyboardState,
            GamePadState gamePadState)
        {
            //Getting analog horizontal movement
            hMovement = gamePadState.ThumbSticks.Left.X * MoveStickScale;

            //Ignoring small movements
            if (Math.Abs(hMovement) < 0.5f)
                hMovement = 0.0f;

            //Button presses
            if (gamePadState.IsButtonDown(Buttons.DPadDown) ||
                keyboardState.IsKeyDown(Keys.Right))
            {
                hMovement = -1.0f;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadDown) ||
              keyboardState.IsKeyDown(Keys.Right))
            {
                hMovement = 1.0f;
            }
        }
        private Point MoveMousePointer(GameTime gameTime, GamePadState pad)
        {
            Vector2 change = new Vector2(0, 0);
              if (pad.IsButtonDown(Buttons.LeftThumbstickUp))
            change.Y -= 1.0f;
              if (pad.IsButtonDown(Buttons.LeftThumbstickDown))
            change.Y += 1.0f;
              if (pad.IsButtonDown(Buttons.LeftThumbstickLeft))
            change.X -= 1.0f;
              if (pad.IsButtonDown(Buttons.LeftThumbstickRight))
            change.X += 1.0f;
              change *= (float)(gameTime.ElapsedGameTime.TotalMilliseconds / 3);

              // Update the OS pointer
              POINT nativePointer;
              GetCursorPos(out nativePointer);
              nativePointer.x += (int)change.X;
              nativePointer.y += (int)change.Y;
              SetCursorPos(nativePointer.x, nativePointer.y);

              MouseState mouse = Mouse.GetState();
              return new Point(mouse.X, mouse.Y);
        }
Example #30
0
        public void Update(GamePadState pad)
        {
            if ((pad.IsButtonDown(Buttons.LeftThumbstickDown) && !oldPad.IsButtonDown(Buttons.LeftThumbstickDown)) || (pad.IsButtonDown(Buttons.DPadDown)) && oldPad.IsButtonUp(Buttons.DPadDown))
            {
                if (current < 3)
                {
                    current++;
                }
            }
            if ((pad.IsButtonDown(Buttons.LeftThumbstickUp) && !oldPad.IsButtonDown(Buttons.LeftThumbstickUp)) || (pad.IsButtonDown(Buttons.DPadUp) && oldPad.IsButtonUp(Buttons.DPadUp)))
            {
                if (current > 1)
                {
                    current--;
                }
            }
            if (pad.IsButtonDown(Buttons.A) && oldPad.IsButtonUp(Buttons.A))
            {
                if (current == 1)
                {
                    FirstGame.start = true;
                    FirstGame.reloadCount = 0;
                    FirstGame.checkpoint = false;
                }
                else if (current == 2)
                {
                    FirstGame.credits = true;
                }
                else if (current == 3)
                {
                    FirstGame.exit = true;
                }
            }

            oldPad = pad;
        }