From c546c69434b36ce3f434905ba58dc7d6f22a102c Mon Sep 17 00:00:00 2001 From: Maddy Thorson Date: Thu, 11 Feb 2021 16:53:19 -0800 Subject: [PATCH] Vector operators. Rect constructor. Scene condition getters --- src/Core/Scene.bf | 16 ++++++++++++++++ src/Struct/Rect.bf | 8 ++++++++ src/Struct/Vector.bf | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/Core/Scene.bf b/src/Core/Scene.bf index d1c60b3..288ae19 100644 --- a/src/Core/Scene.bf +++ b/src/Core/Scene.bf @@ -166,6 +166,14 @@ namespace Strawberry return false; } + public bool Check(Point point, delegate bool(T) condition) where T : Component, IHasHitbox + { + for (T c in componentTracker[typeof(T)]) + if (c.Hitbox.Check(point) && condition(c)) + return true; + return false; + } + public bool Check(Rect rect) where T : Component, IHasHitbox { for (T c in componentTracker[typeof(T)]) @@ -174,6 +182,14 @@ namespace Strawberry return false; } + public bool Check(Rect rect, delegate bool(T) condition) where T : Component, IHasHitbox + { + for (T c in componentTracker[typeof(T)]) + if (c.Hitbox.Check(rect) && condition(c)) + return true; + return false; + } + public T First() where T : Component { for (T c in componentTracker[typeof(T)]) diff --git a/src/Struct/Rect.bf b/src/Struct/Rect.bf index fdd8c0e..f9f5781 100644 --- a/src/Struct/Rect.bf +++ b/src/Struct/Rect.bf @@ -22,6 +22,14 @@ namespace Strawberry Height = height; } + public this(Point pos, int width, int height) + { + X = pos.X; + Y = pos.Y; + Width = width; + Height = height; + } + public this(JSON json) : this(json["x"], json["y"], json["width"], json["height"]) { diff --git a/src/Struct/Vector.bf b/src/Struct/Vector.bf index 0f123b1..5ceebc9 100644 --- a/src/Struct/Vector.bf +++ b/src/Struct/Vector.bf @@ -146,6 +146,18 @@ namespace Strawberry return .(a.X - b.X, a.Y - b.Y); } + [Inline, Commutable] + static public Vector operator*(Vector a, int b) + { + return .(a.X * b, a.Y * b); + } + + [Inline, Commutable] + static public Vector operator/(Vector a, int b) + { + return .(a.X / b, a.Y / b); + } + [Inline, Commutable] static public Vector operator*(Vector a, float b) { @@ -158,6 +170,12 @@ namespace Strawberry return .(a.X / b, a.Y / b); } + [Inline, Commutable] + static public Vector operator*(Vector a, Facings f) + { + return .(a.X * (int)f, a.Y); + } + [Inline] static public Vector operator*(Vector a, Mat3x2 b) {