Time for action – generating falling pieces
Modify the
FillFromAbove()
method of the GameBoard class by adding a call to generate falling pieces right before therowLookup = -1;
line:AddFallingPiece(x, y, GetSquare(x, y), GamePiece.PieceHeight *(y-rowLookup));
Update the
GenerateNewPieces()
method by adding the following call right after theRandomPiece(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 space was at location 5,5 on the board, and the piece above it (5,4) is being moved down one block, the animated piece is created at 5,5 with an offset of 40 pixels (5-4 = 1, times 40).
When new pieces are generated for the board, they are...