コード例 #1
0
        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;
        }