示例#1
0
        public void ProcessControls(GameTime gameTime)
        {
            KeyboardState keyboardState     = Keyboard.GetState();
            bool          isJumpKeyPressed  = keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Space);
            bool          wasJumpKeyPressed = _previousKeyboardState.IsKeyDown(Keys.Up) || _previousKeyboardState.IsKeyDown(Keys.Space);

            if (!wasJumpKeyPressed && isJumpKeyPressed)
            {
                if (_tRex.State != TRexState.Jumping)
                {
                    _tRex.BeginJump();
                }
            }
            else if (_tRex.State == TRexState.Jumping && !isJumpKeyPressed)
            {
                _tRex.CancelJump();
            }
            else if (keyboardState.IsKeyDown(Keys.Down))
            {
                if (_tRex.State == TRexState.Jumping || _tRex.State == TRexState.Falling)
                {
                    _tRex.Drop();
                }
                else
                {
                    _tRex.Duck();
                }
            }
            else if (_tRex.State == TRexState.Ducking && !keyboardState.IsKeyDown(Keys.Down))
            {
                _tRex.GetUp();
            }

            _previousKeyboardState = keyboardState;
        }
        public void ProcessControl(GameTime gametime)
        {
            KeyboardState KeyboardState = Keyboard.GetState();

            bool IsJumpKeyPressed  = KeyboardState.IsKeyDown(Keys.Up) || KeyboardState.IsKeyDown(Keys.Space);
            bool wasJumpKeyPressed = _previouskeyBoradState.IsKeyDown(Keys.Up) || _previouskeyBoradState.IsKeyDown(Keys.Space);

            if (!wasJumpKeyPressed && IsJumpKeyPressed)
            {
                if (_Trex.State != TrexState.jumping)
                {
                    _Trex.StartJumping();
                }
            }

            else if (_Trex.State == TrexState.jumping && !IsJumpKeyPressed)
            {
                _Trex.CancleJump();
            }

            else if (KeyboardState.IsKeyDown(Keys.Down))
            {
                if (_Trex.State == TrexState.jumping || _Trex.State == TrexState.falling)
                {
                    _Trex.Drop();
                }
                else
                {
                    _Trex.Duck();
                }
            }

            else if (_Trex.State == TrexState.ducking && !KeyboardState.IsKeyDown(Keys.Down))
            {
                _Trex.CancleDucking();
            }
            _previouskeyBoradState = KeyboardState;
        }