Vector operators. Rect constructor. Scene condition getters

This commit is contained in:
Maddy Thorson 2021-02-11 16:53:19 -08:00
parent c5ae789804
commit c546c69434
3 changed files with 42 additions and 0 deletions

View File

@ -166,6 +166,14 @@ namespace Strawberry
return false; return false;
} }
public bool Check<T>(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<T>(Rect rect) where T : Component, IHasHitbox public bool Check<T>(Rect rect) where T : Component, IHasHitbox
{ {
for (T c in componentTracker[typeof(T)]) for (T c in componentTracker[typeof(T)])
@ -174,6 +182,14 @@ namespace Strawberry
return false; return false;
} }
public bool Check<T>(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<T>() where T : Component public T First<T>() where T : Component
{ {
for (T c in componentTracker[typeof(T)]) for (T c in componentTracker[typeof(T)])

View File

@ -22,6 +22,14 @@ namespace Strawberry
Height = height; Height = height;
} }
public this(Point pos, int width, int height)
{
X = pos.X;
Y = pos.Y;
Width = width;
Height = height;
}
public this(JSON json) public this(JSON json)
: this(json["x"], json["y"], json["width"], json["height"]) : this(json["x"], json["y"], json["width"], json["height"])
{ {

View File

@ -146,6 +146,18 @@ namespace Strawberry
return .(a.X - b.X, a.Y - b.Y); 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] [Inline, Commutable]
static public Vector operator*(Vector a, float b) static public Vector operator*(Vector a, float b)
{ {
@ -158,6 +170,12 @@ namespace Strawberry
return .(a.X / b, a.Y / b); 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] [Inline]
static public Vector operator*(Vector a, Mat3x2 b) static public Vector operator*(Vector a, Mat3x2 b)
{ {