Time for action – falling pieces

  1. Add a new class to the Flood Control project called "FallingPiece".
  2. Add using Microsoft.Xna.Framework; to the using area at the top of the class.
  3. Update the declaration of the class to read class FallingPiece : GamePiece
  4. Add the following declarations to the FallingPiece class:
    public int VerticalOffset;
    public static int fallRate = 5;
  5. Add a constructor for the FallingPiece class:
    public FallingPiece(string pieceType, int verticalOffset)
        : base(pieceType)
    {
        VerticalOffset = verticalOffset;
    }
  6. Add a method to update the piece:
    public void UpdatePiece()
    {
        VerticalOffset = (int)MathHelper.Max(
            0, 
            VerticalOffset - fallRate);
    }

What just happened?

Simpler than a RotatingPiece, a FallingPiece is also a child of the GamePiece ...

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.