Time for action – falling pieces
Add a new class to the Flood Control project called "FallingPiece".
Add
using Microsoft.Xna.Framework;
to theusing
area at the top of the class.Update the declaration of the class to read
class FallingPiece : GamePiece
Add the following declarations to the FallingPiece class:
public int VerticalOffset; public static int fallRate = 5;
Add a constructor for the FallingPiece class:
public FallingPiece(string pieceType, int verticalOffset) : base(pieceType) { VerticalOffset = verticalOffset; }
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 class. A falling piece has an offset (how high above its final destination it is currently located) and a falling speed (the number of pixels it will move per update).
As with a RotatingPiece, the constructor passes the pieceType...