using System;
namespace Otter {
///
/// Line Collider.
///
public class LineCollider : Collider {
#region Public Fields
///
/// The X position of the end of the line.
///
public float X2;
///
/// The Y position of the end of the line.
///
public float Y2;
#endregion
#region Public Properties
///
/// The width of the area the line occupies.
///
public override float Width {
get { return Math.Abs(X - X2); }
}
///
/// The height of the area the line occupies.
///
public override float Height {
get { return Math.Abs(Y - Y2); }
}
///
/// The bottom most Y position of the line.
///
public override float Bottom {
get { return Math.Max(Y, Y2) - OriginY + Entity.Y; }
}
///
/// The top most Y position of the line.
///
public override float Top {
get { return Math.Min(Y, Y2) - OriginY + Entity.Y; }
}
///
/// The left most X position of the line.
///
public override float Left {
get { return Math.Min(X, X2) - OriginX + Entity.X; }
}
///
/// The right most X position of the line.
///
public override float Right {
get { return Math.Max(X, X2) - OriginX + Entity.X; }
}
///
/// Convert the LineCollider into a Line2 object.
///
public Line2 Line2 {
get { return new Line2(X - OriginX + Entity.X, Y - OriginY + Entity.Y, X2 - OriginX + Entity.X, Y2 - OriginY + Entity.Y); }
}
#endregion
#region Constructors
///
/// Create a LineCollider.
///
/// The X position of the start of the line.
/// The Y position of the start of the line.
/// The X position of the end of the line.
/// The X position of the end of the line.
/// The tags to register for the Collider.
public LineCollider(float x1, float y1, float x2, float y2, params int[] tags) {
X = x1;
Y = y1;
X2 = x2;
Y2 = y2;
AddTag(tags);
}
public LineCollider(float x1, float y1, float x2, float y2, Enum tag, params Enum[] tags) : this(x1, y1, x2, y2) {
AddTag(tag);
AddTag(tags);
}
#endregion
#region Public Methods
///
/// Draw the collider for debug purposes.
///
public override void Render(Color color = null) {
base.Render(color);
if (color == null) color = Color.Red;
if (Entity == null) return;
Draw.Line(Line2.X1, Line2.Y1, Line2.X2, Line2.Y2, color);
}
#endregion
}
}