Time for action - letting the player play

  1. Modify the Update() method of Game1.cs by adding the following before the call to base.Update(gameTime):
    switch (gameState)
    {
    case GameStates.TitleScreen:
    if (Keyboard.GetState().IsKeyDown(Keys.Space))
    {
    gameBoard.ClearBoard();
    gameBoard.GenerateNewPieces(false);
    playerScore = 0;
    gameState = GameStates.Playing;
    }
    break;
    case GameStates.Playing:
    timeSinceLastInput +=
    (float)gameTime.ElapsedGameTime.TotalSeconds;
    if (timeSinceLastInput >= MinTimeSinceLastInput)
    {
    HandleMouseInput(Mouse.GetState());
    }
    gameBoard.ResetWater();
    for (int y = 0; y < GameBoard.GameBoardHeight; y++)
    {
    CheckScoringChain(gameBoard.GetWaterChain(y));
    }
    gameBoard.GenerateNewPieces(true);
    break;
    }
    

What just happened?

The Update() method performs two different functions, depending on the current gameState value. If the game is in TitleScreen state, Update() examines the keyboard, waiting for the Space bar to be pressed. When it is, Update() clears the gameBoard, generates a new set of pieces, resets the player's score, and changes gameState to Playing.

While in the Playing state, Update() accumulates time in timeSinceLastInput in order to pace the game play properly. If enough time has passed, the HandleMouseInput() method is called to allow the player to rotate game pieces.

Update() then calls ResetWater() to clear the water flags for all pieces on the game board. This is followed by a loop that processes each row, starting at the top and working downward, using CheckScoringChain() and GetWaterChain() to "fill" any pieces that should have water in them and check the results of each row for completed chains.

Finally, GenerateNewPieces() is called with the "true" parameter for dropSquares, which will cause GenerateNewPieces() to fill the empty holes from the squares above, and then generate new pipes to replace the empty squares.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.13.201