mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	Collision condition order change. Entity Component getters. Calc.RoundToInt
This commit is contained in:
		@ -298,7 +298,7 @@ namespace Strawberry
 | 
			
		||||
		public bool Check<T>(delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 false;
 | 
			
		||||
@ -307,7 +307,7 @@ namespace Strawberry
 | 
			
		||||
		public bool Check<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 false;
 | 
			
		||||
@ -316,7 +316,7 @@ namespace Strawberry
 | 
			
		||||
		public bool CheckOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 false;
 | 
			
		||||
@ -325,7 +325,7 @@ namespace Strawberry
 | 
			
		||||
		public T First<T>(delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 null;
 | 
			
		||||
@ -334,7 +334,7 @@ namespace Strawberry
 | 
			
		||||
		public T First<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 null;
 | 
			
		||||
@ -343,56 +343,16 @@ namespace Strawberry
 | 
			
		||||
		public T FirstOutside<T>(Point offset, delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 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
 | 
			
		||||
		{
 | 
			
		||||
			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);
 | 
			
		||||
 | 
			
		||||
			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
 | 
			
		||||
		{
 | 
			
		||||
			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);
 | 
			
		||||
 | 
			
		||||
			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
 | 
			
		||||
		{
 | 
			
		||||
			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);
 | 
			
		||||
 | 
			
		||||
			return into;
 | 
			
		||||
 | 
			
		||||
@ -64,6 +64,22 @@ namespace Strawberry
 | 
			
		||||
 | 
			
		||||
		// ===== 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
 | 
			
		||||
		{
 | 
			
		||||
			if (component.Entity == null)
 | 
			
		||||
 | 
			
		||||
@ -204,7 +204,7 @@ namespace Strawberry
 | 
			
		||||
		public T First<T>(Point point, delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 null;
 | 
			
		||||
		}
 | 
			
		||||
@ -220,7 +220,7 @@ namespace Strawberry
 | 
			
		||||
		public T First<T>(Rect rect, delegate bool(T) condition) where T : Component, IHasHitbox
 | 
			
		||||
		{
 | 
			
		||||
			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 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
 | 
			
		||||
		{
 | 
			
		||||
			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);
 | 
			
		||||
			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
 | 
			
		||||
		{
 | 
			
		||||
			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);
 | 
			
		||||
			return into;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,12 @@ namespace Strawberry
 | 
			
		||||
		    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
 | 
			
		||||
		[Inline]
 | 
			
		||||
		static public T Approach<T>(T value, T target, T maxDelta)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user