From c5ae78980435e7186c745c986a4be10283f94fed Mon Sep 17 00:00:00 2001 From: Maddy Thorson Date: Wed, 10 Feb 2021 22:43:09 -0800 Subject: [PATCH] Hitbox helpers --- src/Components/Collision/Hitbox.bf | 222 +++++++++++++++++++++++------ 1 file changed, 182 insertions(+), 40 deletions(-) diff --git a/src/Components/Collision/Hitbox.bf b/src/Components/Collision/Hitbox.bf index de75e71..20490c3 100644 --- a/src/Components/Collision/Hitbox.bf +++ b/src/Components/Collision/Hitbox.bf @@ -62,6 +62,10 @@ namespace Strawberry } } + /* + Edges + */ + public int Left { [Inline] @@ -122,6 +126,184 @@ namespace Strawberry } } + public int CenterX + { + [Inline] + get + { + return Entity.X + Rect.X + Rect.Width / 2; + } + + [Inline] + set + { + Entity.X = value - (Rect.X + Rect.Width / 2); + } + } + + public int CenterY + { + [Inline] + get + { + return Entity.Y + Rect.Y + Rect.Height / 2; + } + + [Inline] + set + { + Entity.Y = value - (Rect.Y + Rect.Height / 2); + } + } + + /* + Points + */ + + public Point TopLeft + { + [Inline] + get + { + return .(Left, Top); + } + + [Inline] + set + { + Left = value.X; + Top = value.Y; + } + } + + public Point TopCenter + { + [Inline] + get + { + return .(CenterX, Top); + } + + [Inline] + set + { + CenterX = value.X; + Top = value.Y; + } + } + + public Point TopRight + { + [Inline] + get + { + return .(Right, Top); + } + + [Inline] + set + { + Right = value.X; + Top = value.Y; + } + } + + public Point CenterLeft + { + [Inline] + get + { + return .(Left, CenterY); + } + + [Inline] + set + { + Left = value.X; + CenterY = value.Y; + } + } + + public Point Center + { + [Inline] + get + { + return .(CenterX, CenterY); + } + + [Inline] + set + { + CenterX = value.X; + CenterY = value.Y; + } + } + + public Point CenterRight + { + [Inline] + get + { + return .(Right, CenterY); + } + + [Inline] + set + { + Right = value.X; + CenterY = value.Y; + } + } + + public Point BottomLeft + { + [Inline] + get + { + return .(Left, Bottom); + } + + [Inline] + set + { + Left = value.X; + Bottom = value.Y; + } + } + + public Point BottomCenter + { + [Inline] + get + { + return .(CenterX, Bottom); + } + + [Inline] + set + { + CenterX = value.X; + Bottom = value.Y; + } + } + + public Point BottomRight + { + [Inline] + get + { + return .(Right, Bottom); + } + + [Inline] + set + { + Right = value.X; + Bottom = value.Y; + } + } + /* Single Collisions */ @@ -244,46 +426,6 @@ namespace Strawberry return null; } - public T LeftmostOutside(Point offset) where T : Component, IHasHitbox - { - T ret = null; - for (var e in Scene.All(scope List())) - if (CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Left < ret.Hitbox.Left)) - ret = e; - - return ret; - } - - public T RightmostOutside(Point offset) where T : Component, IHasHitbox - { - T ret = null; - for (var e in Scene.All(scope List())) - if (CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Right > ret.Hitbox.Right)) - ret = e; - - return ret; - } - - public T TopmostOutside(Point offset) where T : Component, IHasHitbox - { - T ret = null; - for (var e in Scene.All(scope List())) - if (CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Top < ret.Hitbox.Top)) - ret = e; - - return ret; - } - - public T BottommostOutside(Point offset) where T : Component, IHasHitbox - { - T ret = null; - for (var e in Scene.All(scope List())) - if (CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Bottom > ret.Hitbox.Bottom)) - ret = e; - - return ret; - } - public List All(List into) where T : Component, IHasHitbox { for (var e in Scene.All(scope List()))