score renderer
parent
0f6282b049
commit
17bed9c60b
|
@ -4,3 +4,6 @@
|
|||
[submodule "encompass-cs"]
|
||||
path = encompass-cs
|
||||
url = https://gitea.moonside.games/MoonsideGames/encompass-cs.git
|
||||
[submodule "SpriteFontPlus"]
|
||||
path = SpriteFontPlus
|
||||
url = https://github.com/rds1983/SpriteFontPlus.git
|
||||
|
|
Binary file not shown.
|
@ -14,6 +14,7 @@ namespace PongFE.Spawners
|
|||
AddComponent(entity, new CollisionComponent(new MoonTools.Bonk.Rectangle(0, 0, message.Width, message.Height)));
|
||||
AddComponent(entity, new CanDestroyComponent());
|
||||
AddComponent(entity, new ScoreComponent(0));
|
||||
AddComponent(entity, new PlayerComponent(message.PlayerIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,14 @@ namespace PongFE.Messages
|
|||
{
|
||||
public struct GoalBoundarySpawnMessage : IMessage
|
||||
{
|
||||
public PlayerIndex PlayerIndex { get; }
|
||||
public Position2D Position { get; }
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
|
||||
public GoalBoundarySpawnMessage(Position2D position, int width, int height)
|
||||
public GoalBoundarySpawnMessage(PlayerIndex playerIndex, Position2D position, int width, int height)
|
||||
{
|
||||
PlayerIndex = playerIndex;
|
||||
Position = position;
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\FNA\FNA.Core.csproj"/>
|
||||
<ProjectReference Include="..\encompass-cs\encompass-cs\encompass-cs.csproj" />
|
||||
<ProjectReference Include="..\SpriteFontPlus\src\SpriteFontPlus.FNA.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MoonTools.Structs" Version="3.0.1"/>
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\FNA\FNA.csproj"/>
|
||||
<ProjectReference Include="..\encompass-cs\encompass-cs\encompass-cs.csproj"/>
|
||||
<ProjectReference Include="..\SpriteFontPlus\src\SpriteFontPlus.FNA.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MoonTools.Structs" Version="3.0.1"/>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System.IO;
|
||||
using Encompass;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
@ -6,6 +7,7 @@ using PongFE.Enums;
|
|||
using PongFE.Messages;
|
||||
using PongFE.Renderers;
|
||||
using PongFE.Spawners;
|
||||
using SpriteFontPlus;
|
||||
|
||||
namespace PongFE
|
||||
{
|
||||
|
@ -19,6 +21,8 @@ namespace PongFE
|
|||
SpriteBatch SpriteBatch { get; set; }
|
||||
Texture2D WhitePixel { get; set; }
|
||||
|
||||
DynamicSpriteFont ScoreFont { get; set; }
|
||||
|
||||
public PongFEGame()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
|
@ -39,6 +43,8 @@ namespace PongFE
|
|||
WhitePixel = new Texture2D(GraphicsDevice, 1, 1);
|
||||
WhitePixel.SetData(new Color[] { Color.White });
|
||||
|
||||
ScoreFont = DynamicSpriteFont.FromTtf(File.ReadAllBytes(@"Content/Fonts/SquaredDisplay.ttf"), 128);
|
||||
|
||||
WorldBuilder.AddEngine(new InputEngine());
|
||||
WorldBuilder.AddEngine(new PaddleMovementEngine());
|
||||
WorldBuilder.AddEngine(new VelocityEngine());
|
||||
|
@ -57,6 +63,7 @@ namespace PongFE
|
|||
WorldBuilder.AddEngine(new PaddleSpawner(WhitePixel));
|
||||
|
||||
WorldBuilder.AddOrderedRenderer(new Texture2DRenderer(SpriteBatch));
|
||||
WorldBuilder.AddGeneralRenderer(new ScoreRenderer(SpriteBatch, ScoreFont), 0);
|
||||
|
||||
WorldBuilder.SendMessage(
|
||||
new PaddleSpawnMessage(
|
||||
|
@ -108,6 +115,7 @@ namespace PongFE
|
|||
// right boundary
|
||||
WorldBuilder.SendMessage(
|
||||
new GoalBoundarySpawnMessage(
|
||||
Enums.PlayerIndex.One,
|
||||
new MoonTools.Structs.Position2D(1280, 0),
|
||||
6,
|
||||
720
|
||||
|
@ -117,6 +125,7 @@ namespace PongFE
|
|||
// left boundary
|
||||
WorldBuilder.SendMessage(
|
||||
new GoalBoundarySpawnMessage(
|
||||
Enums.PlayerIndex.Two,
|
||||
new MoonTools.Structs.Position2D(-6, 0),
|
||||
6,
|
||||
720
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 0362a4081e41ae6f8b5d78f0ddac7f0240fe8c9f
|
Loading…
Reference in New Issue