当前位置: 首页>>代码示例>>C#>>正文


C# GamePadState.IsButtonUp方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Input.GamePadState.IsButtonUp方法的典型用法代码示例。如果您正苦于以下问题:C# GamePadState.IsButtonUp方法的具体用法?C# GamePadState.IsButtonUp怎么用?C# GamePadState.IsButtonUp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Input.GamePadState的用法示例。


在下文中一共展示了GamePadState.IsButtonUp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

        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();
                }
            }
        }
开发者ID:BoltThrower,项目名称:Super-Mario-World-1-1,代码行数:60,代码来源:GamePadController.cs

示例2: GetInput

        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;
        }
开发者ID:wico-,项目名称:Code,代码行数:27,代码来源:inGamePad.cs

示例3: PerformMove

        public void PerformMove(Move moveToPerform, KeyboardState keyboardStateInput, GamePadState gamepadStateInput)
        {
            if (moveToPerform.name == "RunLeft")
            {
                _speed.X = -1.25f;
                if (gamepadStateInput.IsButtonUp(Buttons.DPadLeft) && gamepadStateInput.IsButtonUp(Buttons.LeftThumbstickLeft) && keyboardStateInput.IsKeyUp(Keys.Left))
                {
                    _speed.X = 0;
                    _playerMostRecentMove = null;
                }
            }
            if (moveToPerform.name == "RunRight")
            {
                _speed.X = 1.25f;
                if (gamepadStateInput.IsButtonUp(Buttons.DPadRight) && gamepadStateInput.IsButtonUp(Buttons.LeftThumbstickRight) && keyboardStateInput.IsKeyUp(Keys.Right))
                {
                    _speed.X = 0;
                    _playerMostRecentMove = null;
                }
            }
            if (moveToPerform.name == "SprintLeft")
            {
                _speed.X = -1.75f;
                if (gamepadStateInput.IsButtonUp(Buttons.DPadLeft) && gamepadStateInput.IsButtonUp(Buttons.LeftThumbstickLeft) && keyboardStateInput.IsKeyUp(Keys.Left))
                {
                    _speed.X = 0;
                    _playerMostRecentMove = null;
                }
            }
            if (moveToPerform.name == "SprintRight")
            {
                _speed.X = 1.75f;
                if (gamepadStateInput.IsButtonUp(Buttons.DPadRight) && gamepadStateInput.IsButtonUp(Buttons.LeftThumbstickRight) && keyboardStateInput.IsKeyUp(Keys.Right))
                {
                    _speed.X = 0;
                    _playerMostRecentMove = null;
                }
            }
            if (moveToPerform.name == "Jump")
            {
                _isJumping = true;
                /*if (gamepadStateInput.IsButtonUp(Buttons.A) && keyboardStateInput.IsKeyUp(Keys.A))
                {
                    isJumping = false;
                    playerMostRecentMove = null;
                }*/

            }
        }
开发者ID:TeamFenixDown,项目名称:ProjectFenixDown,代码行数:49,代码来源:Player.cs

示例4: AttackAdd

        // 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");
            }
        }
开发者ID:nader-dab,项目名称:JustANinjaGame,代码行数:28,代码来源:PlayerLogic.cs

示例5: AmbientToggle

        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();

            }
        }
开发者ID:jsquare89,项目名称:MazeGame,代码行数:32,代码来源:MazeGame.cs

示例6: InputsPlayer

        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);
        }
开发者ID:colincapurso,项目名称:Game-Engine-XNA,代码行数:47,代码来源:Input.cs

示例7: PickupGold

 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();
     }
 }
开发者ID:rpwjanzen,项目名称:2HourGame,代码行数:8,代码来源:ShipControlBehaviours.cs

示例8: IsButtonPressed

 public static bool IsButtonPressed(this GamePadState state, GamePadState oldState, params Buttons[] buttons)
 {
     bool result = false;
     foreach (Buttons button in buttons)
     {
         result = state.IsButtonDown(button) && oldState.IsButtonUp(button);
         if (result)
             break;
     }
     return result;
 }
开发者ID:vorlenko,项目名称:land,代码行数:11,代码来源:KeysExtender.cs

示例9: Update

        // 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;
                        }
                }
            }
        }
开发者ID:fraxouille,项目名称:DirtyTricks,代码行数:40,代码来源:MenuScreen.cs

示例10: Update

        public void Update(GamePadState currentGamePadState, GamePadState previousGamePadState, KeyboardState currentKeyboardState, KeyboardState previousKeyboardState, Game1 game)
        {
            float stickY = currentGamePadState.ThumbSticks.Left.Y;
            spritePosition.Y -= stickY * spriteSpeed;

            if(currentKeyboardState.IsKeyDown(Keys.W))
            {
                spritePosition.Y -= spriteSpeed;
            }
            if (currentKeyboardState.IsKeyDown(Keys.S))
            {
                spritePosition.Y += spriteSpeed;
            }

            if (spritePosition.Y <= 0)
            {
                spritePosition.Y = 0;
            }
            else if (spritePosition.Y >= Game1.SCREEN_HEIGHT - spriteTexture.Height)
            {
                spritePosition.Y = Game1.SCREEN_HEIGHT - spriteTexture.Height;
            }

            if (currentGamePadState.IsButtonDown(Buttons.A) && previousGamePadState.IsButtonUp(Buttons.A))
            {
                if (Ammo > 0)
                {
                    arrows.Add(new Missile(arrowTexture, new Vector2(this.spritePosition.X, this.spritePosition.Y + 13), 8.0f));
                    Ammo--;
                }
            }

            List<Missile> newArrowList = new List<Missile>();

            foreach(Missile arrow in arrows)
            {
                arrow.Update(game);
                if (arrow.getActive())
                {
                    newArrowList.Add(arrow);
                }
            }

            arrows = newArrowList;
        }
开发者ID:rcrichter,项目名称:archery,代码行数:45,代码来源:Player.cs

示例11: CheckGamePadInput

 public void CheckGamePadInput(GamePadState pad, GamePadState padOld, int player)
 {
     Buttons[] buttons = new Buttons[] { Buttons.A, Buttons.B, Buttons.X, Buttons.Y, Buttons.LeftShoulder, Buttons.RightShoulder };
     for (int i = 0; i < 6; i++)
     {
         if (enabledReactions[i] && pad.IsButtonDown(buttons[i]) && padOld.IsButtonUp(buttons[i]) && !hasBeenPressed[player, i])
         {
             reactionTimes[player, i] = "Time: " + timers[i] / 60 + Math.Abs((timers[i] % 60) / 60.0).ToString(".###");
             hasBeenPressed[player, i] = true;
             if (timers[i] >= 0)
                 reactionTimeTotals[player] += timers[i];
             else if (-timers[i] >= 60)
                 reactionTimeTotals[player] += -timers[i];
             else
                 reactionTimeTotals[player] += 60;
         }
     }
 }
开发者ID:DV8FromTheWorld,项目名称:C-Sharp-Programming,代码行数:18,代码来源:Game1.cs

示例12: Update

        /// <summary>
        /// Updates one gamepad state
        /// </summary>
        internal void Update()
        {
            _previousState = _currentState;
            _currentState = XnaGamePad.GetState(_gamePadIndex);

            if (!_previousState.IsConnected)
            {
                if (_currentState.IsConnected)
                {
                    if (Connected != null)
                        Connected(this, new GamePadEventArgs(this));
                }
            }
            else
            {
                if (!_currentState.IsConnected)
                {
                    if (Disconnected != null)
                        Disconnected(this, new GamePadEventArgs(this));
                }
            }
            if (!_currentState.IsConnected) return;

            GamePadThumbSticks prevThumb = _previousState.ThumbSticks;
            GamePadThumbSticks currThumb = _currentState.ThumbSticks;
            _thumbRightDelta = Vector2.Subtract(currThumb.Right, prevThumb.Right);
            _thumbLeftDelta = Vector2.Subtract(currThumb.Left, prevThumb.Left);

            GamePadTriggers prevTrigger = _previousState.Triggers;
            GamePadTriggers currTrigger = _currentState.Triggers;
            _triggerRightDelta = currTrigger.Right - prevTrigger.Right;
            _triggerLeftDelta = currTrigger.Left - prevTrigger.Left;

            InternalButtonPressed.Clear();
            for (short i = 0; i < AllDigital.Length; i++)
            {
                if(_currentState.IsButtonUp(AllDigital[i])) continue;

                AbstractButton btn = new AbstractButton(AllDigital[i]);
                InternalButtonPressed.Add(new ButtonEvent(btn, (short)_gamePadIndex));
            }
        }
开发者ID:Julien-Pires,项目名称:Pulsar,代码行数:45,代码来源:GamePad.cs

示例13: checkGameInput

        private void checkGameInput()
        {
            newState = Keyboard.GetState();
            P1newPadState = GamePad.GetState(PlayerIndex.One);
            P2newPadState = GamePad.GetState(PlayerIndex.Two);

            if (oldState.IsKeyDown(Keys.D) || P1oldPadState.IsButtonDown(Buttons.DPadRight))
            {
                player1.playerShip.physicsObj.body.Rotation += 0.1f;
            }

            if (oldState.IsKeyDown(Keys.A) || P1oldPadState.IsButtonDown(Buttons.DPadLeft))
            {

                player1.playerShip.physicsObj.body.Rotation -= 0.1f;
            }

            if (oldState.IsKeyDown(Keys.W) || P1oldPadState.IsButtonDown(Buttons.DPadUp))
            {
                Ship Player1Ship = player1.playerShip;

                Vector2 direction = new Vector2((float)(Math.Cos(Player1Ship.physicsObj.body.GetAngle())), (float)(Math.Sin(Player1Ship.physicsObj.body.GetAngle())));

                direction.Normalize();

                direction *= shipSpeed;

                Player1Ship.physicsObj.body.ApplyLinearImpulse(direction, Player1Ship.physicsObj.body.GetWorldCenter());

            }

            if ((oldState.IsKeyDown(Keys.X) && newState.IsKeyUp(Keys.X)) || (P1oldPadState.IsButtonDown(Buttons.A) && P1newPadState.IsButtonUp(Buttons.A)))
            {
                player1.createMissile();
            }

            if (oldState.IsKeyDown(Keys.C) && newState.IsKeyUp(Keys.C) || (P1oldPadState.IsButtonDown(Buttons.B) && P1newPadState.IsButtonUp(Buttons.B)))
            {
                if(player1.state == PlayerState.alive)
                    GameObjManager.Instance().createBomb(PlayerID.one);

            }

            if (oldState.IsKeyDown(Keys.Right) || P2oldPadState.IsButtonDown(Buttons.DPadRight))
            {
                player2.playerShip.physicsObj.body.Rotation += 0.1f;

            }

            if (oldState.IsKeyDown(Keys.Left) || P2oldPadState.IsButtonDown(Buttons.DPadLeft))
            {
                player2.playerShip.physicsObj.body.Rotation -= 0.1f;
            }

            if (oldState.IsKeyDown(Keys.Up) || P2oldPadState.IsButtonDown(Buttons.DPadUp))
            {
                Ship Player2Ship = player2.playerShip;

                Vector2 direction = new Vector2((float)(Math.Cos(Player2Ship.physicsObj.body.GetAngle())), (float)(Math.Sin(Player2Ship.physicsObj.body.GetAngle())));

                direction.Normalize();

                direction *= shipSpeed;

                Player2Ship.physicsObj.body.ApplyLinearImpulse(direction, Player2Ship.physicsObj.body.GetWorldCenter());

            }

            if ((oldState.IsKeyDown(Keys.OemQuestion) && newState.IsKeyUp(Keys.OemQuestion)) || (P2oldPadState.IsButtonDown(Buttons.A) && P2newPadState.IsButtonUp(Buttons.A)))
            {
                player2.createMissile();
            }

            if (oldState.IsKeyDown(Keys.OemPeriod) && newState.IsKeyUp(Keys.OemPeriod) || (P2oldPadState.IsButtonDown(Buttons.B) && P2newPadState.IsButtonUp(Buttons.B)))
            {
                if (player2.state == PlayerState.alive && BombManager.Instance().bombAvailable(PlayerID.two))
                    GameObjManager.Instance().createBomb(PlayerID.two);
            }

            else { }

            P1oldPadState = P1newPadState;
            P2oldPadState = P2newPadState;
            oldState = newState;
        }
开发者ID:frobro98,项目名称:School-Projects,代码行数:85,代码来源:Game1.cs

示例14: GetInput

        private void GetInput(GamePadState gamePadState, GameTime gameTime)
        {
            Vector2 leftStick = gamePadState.ThumbSticks.Right;
            Vector2 rightStick = gamePadState.ThumbSticks.Right;
            if (rightStick != Vector2.Zero)
            {
                Rotation = (float)Math.Atan2(rightStick.X, rightStick.Y);
            }

            //Get analog horizontal movement
            movement = gamePadState.ThumbSticks.Left.X * MoveStickScale;

            //Ignore small movements to prevent running in place
            if (Math.Abs(movement) < 0.5f)
                movement = 0.0f;

            // If any digital horizontal movement is found, override the analog movement
            if (gamePadState.IsButtonDown(Buttons.DPadLeft))
                movement = -1.0f;
            else if (gamePadState.IsButtonDown(Buttons.DPadRight))
                movement = 1.0f;

            // Check if the player wants to jump
            isJumping = gamePadState.IsButtonDown(JumpButton);

            // Check if the player wants to shoot
            if (gameTime.TotalGameTime - previousFireTime > fireTime)
            {
                if (gamePadState.IsButtonUp(ShootButton))
                {
                    if (gamePadState.IsButtonDown(Buttons.LeftTrigger))
                    {
                        if (shootHeat < 0)
                            shootHeat = 0;

                        shootHeat -= 0.1f;
                    }
                }

                if (gamePadState.IsButtonDown(ShootButton))
                {
                    if (shootHeat > 5)
                    {
                        shootHeat = 5;
                        shootOverheat = true;
                    }

                    if (shootHeat < 0 || shootHeat == 0)
                    {
                        shootHeat = 0;
                        shootOverheat = false;
                    }

                    if (shootOverheat == false)
                    {
                        AddBullet(Vector2.Zero);
                        previousFireTime = gameTime.TotalGameTime;
                        shootHeat += 0.2f;
                    }
                }
            }
        }
开发者ID:lbhoward,项目名称:Pandamonium,代码行数:62,代码来源:Player.cs

示例15: Movement

        public void Movement(GameTime gameTime)
        {
            _gamePadState = GamePad.GetState(PlayerIndex.One);

            //Press X to Speed Up!
            if (Keyboard.GetState().IsKeyDown(Keys.X) || (_gamePadState.IsButtonDown(Buttons.X)))
            {
                _topSpeed = 5f;
            }
            else
            {
                _topSpeed = 3f;
            }

            //If We reach top speed, we can't increase velocity anymore
            if (_velocity.X < _topSpeed+1&&_velocity.X>-_topSpeed-1)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Left) || (_gamePadState.IsButtonDown(Buttons.DPadLeft)))
                {
                    //Animation stuff
                    if (_canJump)
                    {
                        _currentState = State.RUNNINGLEFT;
                    }

                    _acceleration.X -= .3f;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Right) || (_gamePadState.IsButtonDown(Buttons.DPadRight)))
                {
                    //Animation stuff
                    if (_canJump)
                    {
                        _currentState = State.RUNNINGRIGHT;
                    }
                    _acceleration.X += .3f;
                }
                else
                {
                    //Animation stuff
                    if (_canJump&&(_previousState==State.RUNNINGRIGHT||_previousState==State.JUMPINGRIGHT))
                    {
                        _currentState = State.IDLERIGHT;
                    }
                    if (_canJump && (_previousState == State.RUNNINGLEFT || _previousState == State.JUMPINGLEFT))
                    {
                        _currentState = State.IDLELEFT;
                    }

                    _acceleration.X = 2f * -_velocity.X;
                }

                //Update Velocity
                _velocity.X += _acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else
            {
                //Accounting for top speed on + and -
                if (_velocity.X > -_topSpeed -1)
                    _velocity.X = _topSpeed;
                else
                    _velocity.X = -_topSpeed;

                //Reset Acceleration or bad things happen
                _acceleration.X = 0;
            }

            _lastJump = _velocity.Y;

            //Now for that Y Position...
            if ((Keyboard.GetState().IsKeyDown(Keys.Z)||(_gamePadState.IsButtonDown(Buttons.A))) && _canJump && _noSpamJump)
            {
                _jumpSFX.Play();
                _velocity.Y = -_jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                _canJump = false;
                //Console.WriteLine("Jumped");

                //For Counting Jumps and no spamming
                if (_bruteCount == 0)
                {
                    _noJumps++;
                }
                if (_bruteCount == 3)
                {
                    _noSpamJump = false;
                }

                _bruteCount++;
            }
            //NO SPAM JUMPING
            if (Keyboard.GetState().IsKeyUp(Keys.Z)&&(_gamePadState.IsButtonUp(Buttons.A)))
            {
                _noSpamJump = true;
                _bruteCount = 0;
            }

            //Gravity
            if (!_canJump)
            {
                _velocity.Y += _gravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                _jumpSpeed = 500f;
//.........这里部分代码省略.........
开发者ID:Terracorrupt,项目名称:3rdYearProject,代码行数:101,代码来源:Player.cs


注:本文中的Microsoft.Xna.Framework.Input.GamePadState.IsButtonUp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。