mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	OnCollide component
This commit is contained in:
		
							
								
								
									
										36
									
								
								src/Components/Logic/OnCollide.bf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/Components/Logic/OnCollide.bf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
namespace Strawberry
 | 
			
		||||
{
 | 
			
		||||
	public class OnCollide<T> : Component where T : Entity
 | 
			
		||||
	{
 | 
			
		||||
		// Takes as parameter the T collided with. Return false to stop checking for collisions until next frame.
 | 
			
		||||
		public delegate bool(T) Action;
 | 
			
		||||
 | 
			
		||||
		public this(delegate bool(T) action)
 | 
			
		||||
			: base(true, false)
 | 
			
		||||
		{
 | 
			
		||||
			Action = action;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public override void Started()
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public override void Update()
 | 
			
		||||
		{
 | 
			
		||||
			if (Action != null)
 | 
			
		||||
			{
 | 
			
		||||
				let list = Entity.Scene.All<T>(scope List<T>());
 | 
			
		||||
				for (let t in list)
 | 
			
		||||
					if (Entity.Check(t) && !Action(t))
 | 
			
		||||
						break;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public override void Draw()
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user