48 lines
1.8 KiB
C#
48 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 TitleRenderer : GeneralRenderer
|
|
{
|
|
private SpriteBatch SpriteBatch { get; }
|
|
private DynamicSpriteFont TitleFont { get; }
|
|
private DynamicSpriteFont InstructionFont { get; }
|
|
|
|
public TitleRenderer(SpriteBatch spriteBatch, DynamicSpriteFont titleFont, DynamicSpriteFont instructionFont)
|
|
{
|
|
SpriteBatch = spriteBatch;
|
|
TitleFont = titleFont;
|
|
InstructionFont = instructionFont;
|
|
}
|
|
|
|
public override void Render()
|
|
{
|
|
ref readonly var gameStateComponent = ref ReadComponent<GameStateComponent>();
|
|
ref readonly var playAreaComponent = ref ReadComponent<PlayAreaComponent>();
|
|
|
|
if (gameStateComponent.GameState == GameState.Title)
|
|
{
|
|
var titleDimensions = TitleFont.MeasureString("PongFE");
|
|
var titlePosition = new Vector2(
|
|
(playAreaComponent.Width - titleDimensions.X) / 2,
|
|
(playAreaComponent.Height - titleDimensions.Y) / 4
|
|
);
|
|
|
|
var instructionDimensions = InstructionFont.MeasureString("Press Enter to begin");
|
|
var instructionPosition = new Vector2(
|
|
(playAreaComponent.Width - instructionDimensions.X) / 2,
|
|
playAreaComponent.Height * 2 / 3
|
|
);
|
|
|
|
SpriteBatch.DrawString(TitleFont, "PongFE", titlePosition, Color.White);
|
|
SpriteBatch.DrawString(InstructionFont, "Press Enter to begin", instructionPosition, Color.White);
|
|
}
|
|
}
|
|
}
|
|
}
|