using Microsoft.Xna.Framework
; to the using
area at the top of the class. class FallingPiece : GamePiece
public int VerticalOffset; public static int fallRate = 5;
public FallingPiece(string pieceType, int verticalOffset) : base(pieceType) { VerticalOffset = verticalOffset; }
public void UpdatePiece() { VerticalOffset = (int)MathHelper.Max( 0, VerticalOffset - fallRate); }
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
parameter to its base class constructor and uses the verticalOffset
parameter to set the VerticalOffset
member. Note that the capitalization on these two items differs. Since VerticalOffset
is declared as public and therefore capitalized by common C# convention, there is no need to use the "this" notation, since the two variables technically have different names.
Lastly, the UpdatePiece()
method subtracts fallRate
from VerticalOffset
, again using the MathHelper.Max()
method to ensure the offset does not fall below zero.
3.144.35.148