33 lines
863 B
C#
33 lines
863 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.OnScoresUpdated += 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;
|
|
}
|