using Microsoft.Xna.Framework.Graphics; /** * A sprite that shows the value of an eaten peanut. * * @author Jim Glenn * @version 0.2 2/10/2009 translated to C# (still needs XML comments) * @version 0.1 1/21/2009 */ namespace WindowsGame1 { public class ValueDisplay : Sprite { /** * The value displayed. */ private int value; /** * The default size of a display. */ public const double DefaultSize = 0.03; /** * The default vertical speed of a display. */ public const double DefaultSpeed = -0.03; /** * The default amount of time a display will exist. */ public const double DefaultTime = 1.5; /** * Creates a new sprite that displays the given value. * * @param v the value to display */ public ValueDisplay(double initX, double initY, int v) : base(initX, initY, DefaultSize, 0.0, DefaultSpeed, Color.Black) { value = v; } /** * Returns the value in this display. * * @return the displayed value */ public int GetValue() { return value; } /** * Returns the current color of this display. * * @return the color of this display. */ public override Color GetColor() { return new Color((byte)(GetStateTime() / DefaultTime * 255), (byte)(GetStateTime() / DefaultTime * 255), (byte)(GetStateTime() / DefaultTime * 255)); } /** * Updates this sprite's position and checks for its expiration. * * @param t the time since the last update, in seconds * @param w the world this sprite belongs to */ public override void Update(double t, GameModel m) { base.Update(t, m); // check for expiration if (GetStateTime() > DefaultTime) { m.RemoveSprite(this); } } } }