using System; namespace Otter { /// /// Class used for tracking an X and Y speed of an object. Speed also has an XMax and YMax that can /// be used to clamp the X and Y values automatically. /// public class Speed { float x, y; /// /// The maximum X speed. /// public float MaxX; /// /// The maximum Y speed. /// public float MaxY; /// /// Determines if the maximum values will be hard clamped. /// If true, values will never exceed the maximums. /// public bool HardClamp; /// /// The current X value of the speed. /// public float X { get { if (HardClamp) { return Util.Clamp(x, -MaxX, MaxX); } else { return x; } } set { x = value; } } /// /// The current Y value of the speed. /// public float Y { get { if (HardClamp) { return Util.Clamp(y, -MaxY, MaxY); } else { return y; } } set { y = value; } } /// /// Shortcut to set both MaxX and MaxY. /// public float Max { set { MaxX = value; MaxY = value; } } /// /// The length of the speed object. /// public float Length { get { return (float)Math.Sqrt(X * X + Y * Y); } } /// /// Create a new Speed object. /// /// The initial X value. /// The initial Y value. /// The maximum X value. /// The maximum Y value. /// Determines if the value can exceed the maximum. public Speed(float x, float y, float maxX, float maxY, bool hardClamp) { this.x = x; this.y = y; MaxX = maxX; MaxY = maxY; HardClamp = hardClamp; } /// /// Create a new Speed object. /// /// The initial X value. /// The initial Y value. /// The maximum X value. /// The maximum Y value. public Speed(float x, float y, float maxX, float maxY) : this(x, y, maxX, maxY, true) { } /// /// Create a new Speed object. /// /// The maximum X value. /// The maximum Y value. public Speed(float maxX, float maxY) : this(0, 0, maxX, maxY, true) { } /// /// Create a new Speed object. /// /// The maximum X value. /// The maximum Y value. /// Determines if the value can exceed the maximum. public Speed(float maxX, float maxY, bool hardClamp) : this(0, 0, maxX, maxY, hardClamp) { } /// /// Create a new Speed object. /// /// The maximum X and Y values. /// Determines if the value can exceed the maximum. public Speed(float max, bool hardClamp) : this(0, 0, max, max, hardClamp) { } /// /// Create a new Speed object. /// /// The maximum X and Y values. public Speed(float max) : this(0, 0, max, max, true) { } /// /// Returns a String that represents this instance. /// /// /// A String that represents this instance. /// public override string ToString() { return "X: " + X + " Y: " + Y; } } }