Time for action – generating falling pieces

  1. Modify the FillFromAbove() method of the GameBoard class by adding a call to generate falling pieces right before the rowLookup = -1; line:
    AddFallingPiece(x, y, GetSquare(x, y), 
        GamePiece.PieceHeight *(y-rowLookup));
  2. Update the GenerateNewPieces() method by adding the following call right after the RandomPiece(x,y) line:
    AddFallingPiece(x, y, GetSquare(x, y),
        GamePiece.PieceHeight * GameBoardHeight);

What just happened?

When FillFromAbove() moves a piece downward, we now create an entry in the FallingPieces dictionary that is equivalent to the newly moved piece. The vertical offset is set to the height of a piece (40 pixels) times the number of board squares the piece was moved. For example, if the empty ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.