using Microsoft.Xna.Framework.Graphics; using Syntriax.Engine.Core; namespace Pong.Behaviours; public class TextScoreBehaviour : TextBehaviour { public bool IsLeft { get; } private PongManagerBehaviour? pongManager = null; public TextScoreBehaviour(bool IsLeft) => this.IsLeft = IsLeft; public TextScoreBehaviour(bool IsLeft, SpriteFont font) : base(font) => this.IsLeft = IsLeft; protected override void OnFirstActiveFrame() { if (!GameObject.GameManager.TryFindBehaviour(out pongManager)) return; pongManager.OnScored += UpdateScores; pongManager.OnReset += UpdateScores; UpdateScores(pongManager); } private void UpdateScores(PongManagerBehaviour pongManager) { if (IsLeft) Text = pongManager.ScoreLeft.ToString(); else Text = pongManager.ScoreRight.ToString(); } }