From ca92b12833e684efa55e644f67a5fdd28e1d737b Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 28 Jan 2024 15:33:45 +0300 Subject: [PATCH] feat: Score Boundary --- Game/Behaviours/ScoreBoundary.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Game/Behaviours/ScoreBoundary.cs diff --git a/Game/Behaviours/ScoreBoundary.cs b/Game/Behaviours/ScoreBoundary.cs new file mode 100644 index 0000000..dac1d30 --- /dev/null +++ b/Game/Behaviours/ScoreBoundary.cs @@ -0,0 +1,18 @@ +using System; +using Syntriax.Engine.Core; +using Syntriax.Engine.Physics2D.Abstract; + +namespace Pong.Behaviours; + +public class ScoreBoundary(Action OnCollision) : BehaviourOverride +{ + private Action OnCollision { get; } = OnCollision; + + protected override void OnFirstActiveFrame() + { + if (!BehaviourController.TryGetBehaviour(out ICollider2D? collider2D)) + return; + + collider2D.OnCollisionDetected += (_, _1) => OnCollision?.Invoke(); + } +}