2024-01-30 20:56:43 +03:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2024-01-30 12:43:30 +03:00
|
|
|
using Syntriax.Engine.Core;
|
|
|
|
|
|
|
|
namespace Pong.Behaviours;
|
|
|
|
|
2024-01-31 12:17:43 +03:00
|
|
|
public class TextScoreBehaviour : TextBehaviour
|
2024-01-30 12:43:30 +03:00
|
|
|
{
|
2024-01-30 20:56:43 +03:00
|
|
|
public bool IsLeft { get; }
|
2024-01-30 12:43:30 +03:00
|
|
|
|
2024-01-31 12:17:43 +03:00
|
|
|
private PongManagerBehaviour? pongManager = null;
|
2024-01-30 12:43:30 +03:00
|
|
|
|
|
|
|
protected override void OnFirstActiveFrame()
|
|
|
|
{
|
|
|
|
if (!GameObject.GameManager.TryFindBehaviour(out pongManager))
|
|
|
|
return;
|
|
|
|
|
2024-02-02 12:53:25 +03:00
|
|
|
pongManager.OnFinished += UpdateScores;
|
2024-01-30 12:43:30 +03:00
|
|
|
pongManager.OnScored += UpdateScores;
|
|
|
|
pongManager.OnReset += UpdateScores;
|
2024-01-30 20:56:43 +03:00
|
|
|
|
|
|
|
UpdateScores(pongManager);
|
2024-01-30 12:43:30 +03:00
|
|
|
}
|
|
|
|
|
2024-01-31 12:17:43 +03:00
|
|
|
private void UpdateScores(PongManagerBehaviour pongManager)
|
2024-01-30 12:43:30 +03:00
|
|
|
{
|
|
|
|
if (IsLeft)
|
|
|
|
Text = pongManager.ScoreLeft.ToString();
|
|
|
|
else
|
|
|
|
Text = pongManager.ScoreRight.ToString();
|
|
|
|
}
|
2024-01-31 12:51:23 +03:00
|
|
|
|
|
|
|
public TextScoreBehaviour(bool IsLeft) => this.IsLeft = IsLeft;
|
|
|
|
public TextScoreBehaviour(bool IsLeft, SpriteFont font) : base(font) => this.IsLeft = IsLeft;
|
2024-01-30 12:43:30 +03:00
|
|
|
}
|