using Friflo.Engine.ECS; using Microsoft.Xna.Framework; namespace MrGameEng.Collisions; /// Shape of a . public enum ColliderShape : byte { /// Circle of . Circle, /// Axis-aligned box of . Does not rotate with the entity. Box, } /// /// Collision shape component. Create via or — /// the struct default has no size and collides with nothing. /// Positions come from Transform2D; shifts the shape /// relative to it (entity scale and rotation are not applied to collider shapes). /// public struct Collider : IComponent { /// Shape kind. public ColliderShape Shape; /// Circle radius in world units ( only). public float Radius; /// Half extents of the box ( only). public Vector2 HalfExtents; /// Shape center offset from the entity's transform position. public Vector2 Offset; /// Bit mask of layers this collider belongs to. public uint Layer; /// Bit mask of layers this collider collides with. A pair is reported only when the masks agree both ways. public uint CollidesWith; /// Creates a circle collider on layer 1 colliding with everything. public static Collider Circle(float radius, Vector2 offset = default) => new() { Shape = ColliderShape.Circle, Radius = radius, Offset = offset, Layer = 1, CollidesWith = uint.MaxValue, }; /// Creates a box collider on layer 1 colliding with everything. public static Collider Box(float width, float height, Vector2 offset = default) => new() { Shape = ColliderShape.Box, HalfExtents = new Vector2(width / 2f, height / 2f), Offset = offset, Layer = 1, CollidesWith = uint.MaxValue, }; }