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()) { ref readonly var scoreComponent = ref GetComponent(entity); ref readonly var playerComponent = ref GetComponent(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 ); } } } }