From 9bad58cf2d353919121a7cbcca5d6f85530a6ca9 Mon Sep 17 00:00:00 2001 From: Matt Thorson Date: Fri, 29 May 2020 17:40:31 -0700 Subject: [PATCH] OnCollide component --- src/Components/Logic/OnCollide.bf | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Components/Logic/OnCollide.bf diff --git a/src/Components/Logic/OnCollide.bf b/src/Components/Logic/OnCollide.bf new file mode 100644 index 0000000..b064123 --- /dev/null +++ b/src/Components/Logic/OnCollide.bf @@ -0,0 +1,36 @@ +using System.Collections; +namespace Strawberry +{ + public class OnCollide : 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(scope List()); + for (let t in list) + if (Entity.Check(t) && !Action(t)) + break; + } + } + + public override void Draw() + { + + } + } +}