public bool StartGame() { if (State != GameState.Initial) { return(false); } State = GameState.Transition; _trex.BeginJump(); return(true); }
private bool StartGame() { if (State != GameState.Initial) { return(false); } _scoreBoard.Score = 0; State = GameState.Transition; _trex.BeginJump(); return(true); }
private bool StartGame() { if (State != GameState.Initial) { return(false); } State = GameState.Transition; trex.BeginJump(); _groundManager.Initialize(); _backroundManager.Initilaize(); return(true); }
public void ProcessControls(GameTime gameTime) { KeyboardState keyboardState = Keyboard.GetState(); if (!_isBlocked) { bool isJumpKeyPressed = keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Space); bool wasJumpKeyPressed = _previousKeyboardState.IsKeyDown(Keys.Up) || _previousKeyboardState.IsKeyDown(Keys.Space); if (isJumpKeyPressed && !wasJumpKeyPressed) { if (_trex.State != TrexState.Jumping) { _trex.BeginJump(); } } // if we check _previousKeyboardState.IsKeyDown // Cancel Jump will only be called on the frame the keyboard is released else if (!isJumpKeyPressed && _trex.State == TrexState.Jumping) { _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(); } } // keyboardState is a struct, so it won't be referencing the same instance _previousKeyboardState = keyboardState; _isBlocked = false; }
public void ProcessControls(GameTime gameTime) { KeyboardState keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Up) && !_previousKeyboardState.IsKeyDown(Keys.Up)) { if (_trex.State != TrexState.Jumping) { _trex.BeginJump(); } } else if (!keyboardState.IsKeyDown(Keys.Up) && _trex.State == TrexState.Jumping) { _trex.CancelJump(); } _previousKeyboardState = keyboardState; }
public void ProcessControls(GameTime gameTime) { KeyboardState keyboardState = Keyboard.GetState(); if (!_isBlocked) { 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; _isBlocked = false; }