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