mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Collision condition order change. Entity Component getters. Calc.RoundToInt
This commit is contained in:
parent
86b05c648b
commit
0b39478d1b
|
@ -298,7 +298,7 @@ namespace Strawberry
|
||||||
public bool Check<T>(delegate bool(T) condition) where T : Component, IHasHitbox
|
public bool Check<T>(delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && Check(e.Hitbox))
|
if (Check(e.Hitbox) && condition(e))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -307,7 +307,7 @@ namespace Strawberry
|
||||||
public bool Check<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
public bool Check<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && Check(e.Hitbox, offset))
|
if (Check(e.Hitbox, offset) && condition(e))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -316,7 +316,7 @@ namespace Strawberry
|
||||||
public bool CheckOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
public bool CheckOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && CheckOutside(e.Hitbox, offset))
|
if (CheckOutside(e.Hitbox, offset) && condition(e))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -325,7 +325,7 @@ namespace Strawberry
|
||||||
public T First<T>(delegate bool(T) condition) where T : Component, IHasHitbox
|
public T First<T>(delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && Check(e.Hitbox))
|
if (Check(e.Hitbox) && condition(e))
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -334,7 +334,7 @@ namespace Strawberry
|
||||||
public T First<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
public T First<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && Check(e.Hitbox, offset))
|
if (Check(e.Hitbox, offset) && condition(e))
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -343,56 +343,16 @@ namespace Strawberry
|
||||||
public T FirstOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
public T FirstOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && CheckOutside(e.Hitbox, offset))
|
if (CheckOutside(e.Hitbox, offset) && condition(e))
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T LeftmostOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
|
||||||
{
|
|
||||||
T ret = null;
|
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
|
||||||
if (condition(e) && CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Left < ret.Hitbox.Left))
|
|
||||||
ret = e;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T RightmostOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
|
||||||
{
|
|
||||||
T ret = null;
|
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
|
||||||
if (condition(e) && CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Right > ret.Hitbox.Right))
|
|
||||||
ret = e;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T TopmostOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
|
||||||
{
|
|
||||||
T ret = null;
|
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
|
||||||
if (condition(e) && CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Top < ret.Hitbox.Top))
|
|
||||||
ret = e;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T BottommostOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
|
|
||||||
{
|
|
||||||
T ret = null;
|
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
|
||||||
if (condition(e) && CheckOutside(e.Hitbox, offset) && (ret == null || e.Hitbox.Bottom > ret.Hitbox.Bottom))
|
|
||||||
ret = e;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> All<T>(List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
public List<T> All<T>(List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && Check(e.Hitbox))
|
if (Check(e.Hitbox) && condition(e))
|
||||||
into.Add(e);
|
into.Add(e);
|
||||||
|
|
||||||
return into;
|
return into;
|
||||||
|
@ -401,7 +361,7 @@ namespace Strawberry
|
||||||
public List<T> All<T>(Point offset, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
public List<T> All<T>(Point offset, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && Check(e.Hitbox, offset))
|
if (Check(e.Hitbox, offset) && condition(e))
|
||||||
into.Add(e);
|
into.Add(e);
|
||||||
|
|
||||||
return into;
|
return into;
|
||||||
|
@ -410,7 +370,7 @@ namespace Strawberry
|
||||||
public List<T> AllOutside<T>(Point offset, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
public List<T> AllOutside<T>(Point offset, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (var e in Scene.All<T>(scope List<T>()))
|
for (var e in Scene.All<T>(scope List<T>()))
|
||||||
if (condition(e) && CheckOutside(e.Hitbox, offset))
|
if (CheckOutside(e.Hitbox, offset) && condition(e))
|
||||||
into.Add(e);
|
into.Add(e);
|
||||||
|
|
||||||
return into;
|
return into;
|
||||||
|
|
|
@ -64,6 +64,22 @@ namespace Strawberry
|
||||||
|
|
||||||
// ===== Components =====
|
// ===== Components =====
|
||||||
|
|
||||||
|
public T First<T>() where T : Component
|
||||||
|
{
|
||||||
|
for (let c in components)
|
||||||
|
if (c is T)
|
||||||
|
return c as T;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> All<T>(List<T> into) where T : Component
|
||||||
|
{
|
||||||
|
for (let c in components)
|
||||||
|
if (c is T)
|
||||||
|
into.Add(c as T);
|
||||||
|
return into;
|
||||||
|
}
|
||||||
|
|
||||||
public T Add<T>(T component) where T : Component
|
public T Add<T>(T component) where T : Component
|
||||||
{
|
{
|
||||||
if (component.Entity == null)
|
if (component.Entity == null)
|
||||||
|
|
|
@ -204,7 +204,7 @@ namespace Strawberry
|
||||||
public T First<T>(Point point, delegate bool(T) condition) where T : Component, IHasHitbox
|
public T First<T>(Point point, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (T c in componentTracker[typeof(T)])
|
for (T c in componentTracker[typeof(T)])
|
||||||
if (condition(c) && c.Hitbox.Check(point))
|
if (c.Hitbox.Check(point) && condition(c))
|
||||||
return c as T;
|
return c as T;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ namespace Strawberry
|
||||||
public T First<T>(Rect rect, delegate bool(T) condition) where T : Component, IHasHitbox
|
public T First<T>(Rect rect, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (T c in componentTracker[typeof(T)])
|
for (T c in componentTracker[typeof(T)])
|
||||||
if (condition(c) && c.Hitbox.Check(rect))
|
if (c.Hitbox.Check(rect) && condition(c))
|
||||||
return c as T;
|
return c as T;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ namespace Strawberry
|
||||||
public List<T> All<T>(Point point, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
public List<T> All<T>(Point point, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (T c in componentTracker[typeof(T)])
|
for (T c in componentTracker[typeof(T)])
|
||||||
if (condition(c) && c.Hitbox.Check(point))
|
if (c.Hitbox.Check(point) && condition(c))
|
||||||
into.Add(c as T);
|
into.Add(c as T);
|
||||||
return into;
|
return into;
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ namespace Strawberry
|
||||||
public List<T> All<T>(Rect rect, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
public List<T> All<T>(Rect rect, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
|
||||||
{
|
{
|
||||||
for (T c in componentTracker[typeof(T)])
|
for (T c in componentTracker[typeof(T)])
|
||||||
if (condition(c) && c.Hitbox.Check(rect))
|
if (c.Hitbox.Check(rect) && condition(c))
|
||||||
into.Add(c as T);
|
into.Add(c as T);
|
||||||
return into;
|
return into;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,12 @@ namespace Strawberry
|
||||||
return (bits & (1 << pos)) != 0;
|
return (bits & (1 << pos)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
static public int RoundToInt(float f)
|
||||||
|
{
|
||||||
|
return (int)Math.Round(f);
|
||||||
|
}
|
||||||
|
|
||||||
//Move toward a target value without crossing it
|
//Move toward a target value without crossing it
|
||||||
[Inline]
|
[Inline]
|
||||||
static public T Approach<T>(T value, T target, T maxDelta)
|
static public T Approach<T>(T value, T target, T maxDelta)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user