34 lines
880 B
C#
34 lines
880 B
C#
using Microsoft.Xna.Framework.Graphics;
|
|
using Syntriax.Engine.Core;
|
|
|
|
namespace Pong.Behaviours;
|
|
|
|
public class PongTextBehaviour : TextBehaviour
|
|
{
|
|
public bool IsLeft { get; }
|
|
|
|
private PongManager? pongManager = null;
|
|
|
|
public PongTextBehaviour(bool IsLeft) => this.IsLeft = IsLeft;
|
|
public PongTextBehaviour(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(PongManager pongManager)
|
|
{
|
|
if (IsLeft)
|
|
Text = pongManager.ScoreLeft.ToString();
|
|
else
|
|
Text = pongManager.ScoreRight.ToString();
|
|
}
|
|
}
|