63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using Encompass;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using PongFE.Components;
|
|
using PongFE.Enums;
|
|
using SpriteFontPlus;
|
|
|
|
namespace PongFE.Renderers
|
|
{
|
|
public class ScoreRenderer : GeneralRenderer
|
|
{
|
|
public SpriteBatch SpriteBatch { get; }
|
|
public DynamicSpriteFont Font { get; }
|
|
|
|
public ScoreRenderer(SpriteBatch spriteBatch, DynamicSpriteFont font)
|
|
{
|
|
SpriteBatch = spriteBatch;
|
|
Font = font;
|
|
}
|
|
|
|
public override void Render()
|
|
{
|
|
int? playerOneScore = null;
|
|
int? playerTwoScore = null;
|
|
|
|
foreach (ref readonly var entity in ReadEntities<ScoreComponent>())
|
|
{
|
|
ref readonly var scoreComponent = ref GetComponent<ScoreComponent>(entity);
|
|
ref readonly var playerComponent = ref GetComponent<PlayerComponent>(entity);
|
|
|
|
if (playerComponent.PlayerIndex == Enums.PlayerIndex.One)
|
|
{
|
|
playerOneScore = scoreComponent.Score;
|
|
}
|
|
else if (playerComponent.PlayerIndex == Enums.PlayerIndex.Two)
|
|
{
|
|
playerTwoScore = scoreComponent.Score;
|
|
}
|
|
}
|
|
|
|
if (playerOneScore.HasValue)
|
|
{
|
|
SpriteBatch.DrawString(
|
|
Font,
|
|
playerOneScore.Value.ToString(),
|
|
new Vector2(400, 20),
|
|
Color.White
|
|
);
|
|
}
|
|
|
|
if (playerTwoScore.HasValue)
|
|
{
|
|
SpriteBatch.DrawString(
|
|
Font,
|
|
playerTwoScore.Value.ToString(),
|
|
new Vector2(880 - 64, 20),
|
|
Color.White
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|