Пример #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;
        }
Пример #2
0
        private bool StartGame()
        {
            if (State != GameState.Initial)
            {
                return(false);
            }

            State = GameState.Transition;
            _tRex.BeginJump();

            return(true);
        }