35 lines
934 B
C#
35 lines
934 B
C#
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using Syntriax.Engine.Core;
|
|
using Syntriax.Engine.Integration.MonoGame;
|
|
|
|
namespace Pong.Behaviours;
|
|
|
|
public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate
|
|
{
|
|
public readonly bool IsLeft = IsLeft;
|
|
|
|
private PongManager pongManager = null!;
|
|
|
|
public void FirstActiveFrame()
|
|
{
|
|
MonoGameWindow monoGameWindow = Universe.FindRequiredBehaviour<MonoGameWindowContainer>().Window;
|
|
Font = monoGameWindow.Content.Load<SpriteFont>("UbuntuMono");
|
|
|
|
pongManager = Universe.FindRequiredBehaviour<PongManager>();
|
|
|
|
pongManager.OnScoreUpdated += UpdateScores;
|
|
pongManager.OnReset += UpdateScores;
|
|
|
|
UpdateScores(pongManager);
|
|
}
|
|
|
|
private void UpdateScores(PongManager pongManager)
|
|
{
|
|
if (IsLeft)
|
|
Text = pongManager.ScoreLeft.ToString();
|
|
else
|
|
Text = pongManager.ScoreRight.ToString();
|
|
}
|
|
}
|