initial paddle drawing
parent
b4993eaeb8
commit
f1cb6fe9ec
|
@ -3,6 +3,8 @@
|
||||||
##
|
##
|
||||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
fnalibs/
|
||||||
|
|
||||||
# User-specific files
|
# User-specific files
|
||||||
*.rsuser
|
*.rsuser
|
||||||
*.suo
|
*.suo
|
||||||
|
|
|
@ -4,3 +4,6 @@
|
||||||
[submodule "encompass-cs"]
|
[submodule "encompass-cs"]
|
||||||
path = encompass-cs
|
path = encompass-cs
|
||||||
url = https://gitea.moonside.games/MoonsideGames/encompass-cs.git
|
url = https://gitea.moonside.games/MoonsideGames/encompass-cs.git
|
||||||
|
[submodule "MoonTools.Structs"]
|
||||||
|
path = MoonTools.Structs
|
||||||
|
url = git@gitea.moonside.games:MoonsideGames/MoonTools.Structs.git
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit a3a5803961d5f172a2376f7b0451ba21bd5842b6
|
|
@ -0,0 +1,15 @@
|
||||||
|
using Encompass;
|
||||||
|
using MoonTools.Structs;
|
||||||
|
|
||||||
|
namespace PongFE.Components
|
||||||
|
{
|
||||||
|
public struct PositionComponent : IComponent
|
||||||
|
{
|
||||||
|
public Position2D Position { get; }
|
||||||
|
|
||||||
|
public PositionComponent(Position2D position)
|
||||||
|
{
|
||||||
|
Position = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
using Encompass;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace PongFE.Components
|
||||||
|
{
|
||||||
|
public struct Texture2DComponent : IComponent, IDrawableComponent
|
||||||
|
{
|
||||||
|
public Texture2D Texture { get; }
|
||||||
|
public int Layer { get; }
|
||||||
|
|
||||||
|
public Texture2DComponent(Texture2D texture, int layer)
|
||||||
|
{
|
||||||
|
Texture = texture;
|
||||||
|
Layer = layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
using MoonTools.Structs;
|
||||||
|
|
||||||
|
namespace PongFE.Extensions
|
||||||
|
{
|
||||||
|
public static class Position2DExtensions
|
||||||
|
{
|
||||||
|
public static Microsoft.Xna.Framework.Vector2 ToXNAVector(this Position2D position)
|
||||||
|
{
|
||||||
|
return new Microsoft.Xna.Framework.Vector2(position.X, position.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\FNA\FNA.Core.csproj"/>
|
<ProjectReference Include="..\FNA\FNA.Core.csproj"/>
|
||||||
<ProjectReference Include="..\encompass-cs\encompass-cs\encompass-cs.csproj" />
|
<ProjectReference Include="..\encompass-cs\encompass-cs\encompass-cs.csproj" />
|
||||||
|
<ProjectReference Include="..\MoonTools.Structs\Structs\Structs.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="..\build\CopyFNALibs.targets"/>
|
<Import Project="..\build\CopyFNALibs.targets"/>
|
||||||
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
|
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\FNA\FNA.csproj"/>
|
<ProjectReference Include="..\FNA\FNA.csproj"/>
|
||||||
<ProjectReference Include="..\encompass-cs\encompass-cs\encompass-cs.csproj" />
|
<ProjectReference Include="..\encompass-cs\encompass-cs\encompass-cs.csproj" />
|
||||||
|
<ProjectReference Include="..\MoonTools.Structs\Structs\Structs.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="..\build\CopyFNALibs.targets"/>
|
<Import Project="..\build\CopyFNALibs.targets"/>
|
||||||
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
|
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using Encompass;
|
using Encompass;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using PongFE.Components;
|
||||||
|
using PongFE.Renderers;
|
||||||
|
|
||||||
namespace PongFE
|
namespace PongFE
|
||||||
{
|
{
|
||||||
|
@ -11,6 +13,10 @@ namespace PongFE
|
||||||
WorldBuilder WorldBuilder { get; } = new WorldBuilder();
|
WorldBuilder WorldBuilder { get; } = new WorldBuilder();
|
||||||
World World { get; set; }
|
World World { get; set; }
|
||||||
|
|
||||||
|
SpriteBatch SpriteBatch { get; set; }
|
||||||
|
Texture2D WhitePixel { get; set; }
|
||||||
|
RenderTarget2D PaddleTexture { get; set; }
|
||||||
|
|
||||||
public PongFEGame()
|
public PongFEGame()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
|
@ -25,6 +31,24 @@ namespace PongFE
|
||||||
|
|
||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
{
|
{
|
||||||
|
SpriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
|
|
||||||
|
WhitePixel = new Texture2D(GraphicsDevice, 1, 1);
|
||||||
|
WhitePixel.SetData(new Color[] { Color.White });
|
||||||
|
|
||||||
|
PaddleTexture = new RenderTarget2D(GraphicsDevice, 20, 80);
|
||||||
|
GraphicsDevice.SetRenderTarget(PaddleTexture);
|
||||||
|
SpriteBatch.Begin();
|
||||||
|
SpriteBatch.Draw(WhitePixel, new Rectangle(0, 0, 20, 80), Color.White);
|
||||||
|
SpriteBatch.End();
|
||||||
|
GraphicsDevice.SetRenderTarget(null);
|
||||||
|
|
||||||
|
WorldBuilder.AddOrderedRenderer(new Texture2DRenderer(SpriteBatch));
|
||||||
|
|
||||||
|
var paddle = WorldBuilder.CreateEntity();
|
||||||
|
WorldBuilder.SetComponent(paddle, new PositionComponent(new MoonTools.Structs.Position2D(5, 5)));
|
||||||
|
WorldBuilder.SetComponent(paddle, new Texture2DComponent(PaddleTexture, 0));
|
||||||
|
|
||||||
World = WorldBuilder.Build();
|
World = WorldBuilder.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +66,11 @@ namespace PongFE
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
GraphicsDevice.Clear(Color.Black);
|
||||||
|
|
||||||
|
SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
|
||||||
World.Draw();
|
World.Draw();
|
||||||
|
SpriteBatch.End();
|
||||||
|
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
using Encompass;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using PongFE.Components;
|
||||||
|
using PongFE.Extensions;
|
||||||
|
|
||||||
|
namespace PongFE.Renderers
|
||||||
|
{
|
||||||
|
public class Texture2DRenderer : OrderedRenderer<Texture2DComponent>
|
||||||
|
{
|
||||||
|
private readonly SpriteBatch _spriteBatch;
|
||||||
|
|
||||||
|
public Texture2DRenderer(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
_spriteBatch = spriteBatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Render(Entity entity, in Texture2DComponent textureComponent)
|
||||||
|
{
|
||||||
|
ref readonly var positionComponent = ref GetComponent<PositionComponent>(entity);
|
||||||
|
|
||||||
|
_spriteBatch.Draw(
|
||||||
|
textureComponent.Texture,
|
||||||
|
positionComponent.Position.Truncated().ToXNAVector(),
|
||||||
|
null,
|
||||||
|
Color.White,
|
||||||
|
0,
|
||||||
|
Vector2.Zero,
|
||||||
|
Vector2.One,
|
||||||
|
SpriteEffects.None,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue