feat: Apo.Shapes Added
This commit is contained in:
parent
40903eacc3
commit
04653711e9
2
Engine
2
Engine
|
@ -1 +1 @@
|
|||
Subproject commit 5ed7ccdded04e075dca04ef93f3c75aefa338566
|
||||
Subproject commit e5732f0ac57886f1b127e154d52b6a9655d7bf85
|
|
@ -0,0 +1,8 @@
|
|||
using Apos.Shapes;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public interface IDisplayableShape
|
||||
{
|
||||
void Draw(ShapeBatch shapeBatch);
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Apos.Shapes;
|
||||
|
||||
using Engine.Physics2D;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Physics2D.Primitives;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class ShapeBehaviour : BehaviourOverride, IDisplayableShape
|
||||
{
|
||||
private readonly List<Vector2D> vectors = [];
|
||||
|
||||
public ShapeBehaviour(Shape Shape) { this.Shape = Shape; }
|
||||
public ShapeBehaviour(Shape Shape, float Thickness) { this.Shape = Shape; this.Thickness = Thickness; }
|
||||
public ShapeBehaviour(Shape Shape, Color color) { this.Shape = Shape; Color = color; }
|
||||
public ShapeBehaviour(Shape Shape, Color color, float Thickness) { this.Shape = Shape; this.Thickness = Thickness; Color = color; }
|
||||
|
||||
public Shape Shape { get; } = default!;
|
||||
public Color Color { get; set; } = Color.White;
|
||||
public float Thickness { get; set; } = .5f;
|
||||
|
||||
public void Draw(ShapeBatch shapeBatch)
|
||||
{
|
||||
Shape.TransformShape(GameObject.Transform, vectors);
|
||||
|
||||
for (int i = 0; i < vectors.Count - 1; i++)
|
||||
shapeBatch.DrawLine(vectors[i].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), vectors[i + 1].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), Thickness, Color, Color);
|
||||
shapeBatch.DrawLine(vectors[0].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), vectors[^1].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), Thickness, Color, Color);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShapeTransform
|
||||
{
|
||||
public static void TransformShape(this Shape shape, ITransform transform, List<Vector2D> vectors)
|
||||
{
|
||||
vectors.Clear();
|
||||
|
||||
int count = shape.Vertices.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
vectors.Add
|
||||
(
|
||||
shape[i]
|
||||
.Scale(transform.Scale)
|
||||
.Rotate(transform.Rotation * Physics2D.DegreeToRadian)
|
||||
.Add(transform.Position)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -20,12 +20,14 @@
|
|||
<EmbeddedResource Include="Icon.bmp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Apos.Shapes" Version="0.2.3" />
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
|
||||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Engine\Engine.Core\Engine.Core.csproj" />
|
||||
<ProjectReference Include="..\Engine\Engine.Input\Engine.Input.csproj" />
|
||||
<ProjectReference Include="..\Engine\Engine.Physics2D\Engine.Physics2D.csproj" />
|
||||
</ItemGroup>
|
||||
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
|
||||
<Message Text="Restoring dotnet tools" Importance="High" />
|
||||
|
|
|
@ -3,9 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Game", "Game.csproj", "{42644486-9F9E-4242-B6C4-AF31BBFA31D2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Core", "..\Engine\Engine.Core\Engine.Core.csproj", "{EF1FE4A2-40DF-4967-8003-CF6D98010D02}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Game", "Game.csproj", "{5C2459D3-9CB7-4778-BBDC-4F5B8298AACD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -13,19 +11,15 @@ Global
|
|||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{42644486-9F9E-4242-B6C4-AF31BBFA31D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{42644486-9F9E-4242-B6C4-AF31BBFA31D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{42644486-9F9E-4242-B6C4-AF31BBFA31D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{42644486-9F9E-4242-B6C4-AF31BBFA31D2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EF1FE4A2-40DF-4967-8003-CF6D98010D02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EF1FE4A2-40DF-4967-8003-CF6D98010D02}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EF1FE4A2-40DF-4967-8003-CF6D98010D02}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EF1FE4A2-40DF-4967-8003-CF6D98010D02}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5C2459D3-9CB7-4778-BBDC-4F5B8298AACD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5C2459D3-9CB7-4778-BBDC-4F5B8298AACD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5C2459D3-9CB7-4778-BBDC-4F5B8298AACD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5C2459D3-9CB7-4778-BBDC-4F5B8298AACD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {AB3225EE-1621-439F-8F83-DF4515922FEF}
|
||||
SolutionGuid = {5C7F09EA-E22F-4BDB-A0F1-1F295EBCE4A0}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
104
Game/Game1.cs
104
Game/Game1.cs
|
@ -4,10 +4,10 @@ using Microsoft.Xna.Framework.Graphics;
|
|||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
using Pong.Behaviours;
|
||||
using Apos.Shapes;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Graphics.TwoDimensional;
|
||||
using Syntriax.Engine.Physics2D;
|
||||
using Syntriax.Engine.Physics2D.Primitives;
|
||||
|
||||
|
@ -18,6 +18,7 @@ public class Game1 : Game
|
|||
private GraphicsDeviceManager _graphics = null!;
|
||||
private PhysicsEngine2D engine;
|
||||
private SpriteBatch _spriteBatch = null!;
|
||||
private ShapeBatch _shapeBatch = null!;
|
||||
public static GameManager gameManager = null!;
|
||||
public static Sprite spriteBox = null!;
|
||||
private MonoGameCameraBehaviour cameraBehaviour = null!;
|
||||
|
@ -30,7 +31,8 @@ public class Game1 : Game
|
|||
_graphics = new GraphicsDeviceManager(this)
|
||||
{
|
||||
PreferredBackBufferWidth = 1024,
|
||||
PreferredBackBufferHeight = 576
|
||||
PreferredBackBufferHeight = 576,
|
||||
GraphicsProfile = GraphicsProfile.HiDef
|
||||
};
|
||||
|
||||
Content.RootDirectory = "Content";
|
||||
|
@ -50,9 +52,10 @@ public class Game1 : Game
|
|||
protected override void LoadContent()
|
||||
{
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
_shapeBatch = new ShapeBatch(GraphicsDevice, Content);
|
||||
|
||||
spriteBox = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") };
|
||||
Sprite spriteBall = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Circle") };
|
||||
// spriteBox = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") };
|
||||
// Sprite spriteBall = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Circle") };
|
||||
|
||||
IGameObject gameObjectCamera = gameManager.InstantiateGameObject<GameObject>();
|
||||
gameObjectCamera.Name = "Camera";
|
||||
|
@ -62,76 +65,14 @@ public class Game1 : Game
|
|||
cameraBehaviour.Viewport = GraphicsDevice.Viewport;
|
||||
gameManager.Camera = cameraBehaviour;
|
||||
|
||||
GameObject gameObjectBall = gameManager.InstantiateGameObject<GameObject>();
|
||||
gameObjectBall.Name = "Ball";
|
||||
gameObjectBall.Transform.Position = Vector2D.Zero;
|
||||
gameObjectBall.Transform.Scale = new Vector2D(1f / 51.2f, 1f / 51.2f);
|
||||
engine.AddRigidBody(gameObjectBall.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2D(.1f, .1f), 500f);
|
||||
gameObjectBall.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBall);
|
||||
gameObjectBall.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * 512f * .5f, Vector2D.One * 512f * .5f);
|
||||
// gameObjectBall = gameManager.InstantiateGameObject<GameObject>();
|
||||
// gameObjectBall.Name = "Ball";
|
||||
// gameObjectBall.Transform.Position = Vector2D.UnitY * 30f;
|
||||
// gameObjectBall.Transform.Scale = new Vector2D(1f / 51.2f, 1f / 51.2f);
|
||||
// engine.AddRigidBody(gameObjectBall.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
// gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2D(.1f, .01f), 500f);
|
||||
// gameObjectBall.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBall);
|
||||
// gameObjectBall.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * 512f * .5f, Vector2D.One * 512f * .5f);
|
||||
|
||||
// IGameObject gameObjectLeft = gameManager.InstantiateGameObject<GameObject>();
|
||||
// gameObjectLeft.Name = "Left";
|
||||
// gameObjectLeft.Transform.Position = new Vector2D(-452, 0f);
|
||||
// gameObjectLeft.Transform.Scale = new Vector2D(10f, 40f);
|
||||
// gameObjectLeft.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
||||
// gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
|
||||
// gameObjectLeft.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
||||
// gameObjectLeft.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * .5f, Vector2D.One * .5f);
|
||||
// engine.AddRigidBody(gameObjectLeft.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
|
||||
// IGameObject gameObjectRight = gameManager.InstantiateGameObject<GameObject>();
|
||||
// gameObjectRight.Name = "Right";
|
||||
// gameObjectRight.Transform.Position = new Vector2D(452, 0f);
|
||||
// gameObjectRight.Transform.Scale = new Vector2D(10f, 40f);
|
||||
// gameObjectRight.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
||||
// gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 268f, -268f, 400f);
|
||||
// gameObjectRight.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
||||
// gameObjectRight.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * .5f, Vector2D.One * .5f);
|
||||
// engine.AddRigidBody(gameObjectRight.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
|
||||
|
||||
IGameObject goPlayAreaTop = gameManager.InstantiateGameObject<GameObject>();
|
||||
goPlayAreaTop.Transform.Position = new Vector2D(0f, 288f + 20f);
|
||||
goPlayAreaTop.Transform.Scale = new Vector2D(10240f, 40f);
|
||||
goPlayAreaTop.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
||||
goPlayAreaTop.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * .5f, Vector2D.One * .5f);
|
||||
engine.AddRigidBody(goPlayAreaTop.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
IGameObject goPlayAreaBottom = gameManager.InstantiateGameObject<GameObject>();
|
||||
goPlayAreaBottom.Transform.Position = new Vector2D(0f, -(288f + 20f));
|
||||
goPlayAreaBottom.Transform.Scale = new Vector2D(10240f, 40f);
|
||||
goPlayAreaBottom.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
||||
goPlayAreaBottom.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * .5f, Vector2D.One * .5f);
|
||||
engine.AddRigidBody(goPlayAreaBottom.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
|
||||
IGameObject goPlayAreaRight = gameManager.InstantiateGameObject<GameObject>();
|
||||
goPlayAreaRight.Transform.Position = new Vector2D(512f + 20f, 0f);
|
||||
goPlayAreaRight.Transform.Scale = new Vector2D(40f, 5760f);
|
||||
goPlayAreaRight.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
||||
goPlayAreaRight.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * .5f, Vector2D.One * .5f);
|
||||
engine.AddRigidBody(goPlayAreaRight.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
IGameObject goPlayAreaLeft = gameManager.InstantiateGameObject<GameObject>();
|
||||
goPlayAreaLeft.Transform.Position = new Vector2D(-(512f + 20f), 0f);
|
||||
goPlayAreaLeft.Transform.Scale = new Vector2D(40f, 5760f);
|
||||
goPlayAreaLeft.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
||||
goPlayAreaLeft.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2D.One * .5f, Vector2D.One * .5f);
|
||||
engine.AddRigidBody(goPlayAreaLeft.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
|
||||
// IGameObject goPlayAreaCenter = gameManager.InstantiateGameObject<GameObject>();
|
||||
// goPlayAreaCenter.Transform.Position = new Vector2D(100f, 100f);
|
||||
// goPlayAreaCenter.Transform.Scale = new Vector2D(40f, 40f);
|
||||
// // goPlayAreaCenter.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
||||
// engine.AddRigidBody(goPlayAreaCenter.BehaviourController.AddBehaviour<RigidBody2D>());
|
||||
// TODO: use this.Content to load your game content here
|
||||
gameObjectDiamond = gameManager.InstantiateGameObject<GameObject>();
|
||||
gameObjectDiamond.Name = "Diamond";
|
||||
gameObjectDiamond.Transform.Position = new Vector2D(0f, 0f);
|
||||
gameObjectDiamond.Transform.Scale = new Vector2D(100f, 100f);
|
||||
gameObjectDiamond.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
||||
gameObjectDiamond.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
|
||||
gameObjectDiamond.BehaviourController.AddBehaviour<ShapeBehaviour>(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Left]));
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
|
@ -165,6 +106,10 @@ public class Game1 : Game
|
|||
cameraBehaviour.BehaviourController.GameObject.Transform.Rotation += gameTime.ElapsedGameTime.Nanoseconds * 0.000025f;
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.E))
|
||||
cameraBehaviour.BehaviourController.GameObject.Transform.Rotation -= gameTime.ElapsedGameTime.Nanoseconds * 0.000025f;
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.NumPad4))
|
||||
gameObjectDiamond.Transform.Rotation += gameTime.ElapsedGameTime.Nanoseconds * 0.0025f;
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.NumPad6))
|
||||
gameObjectDiamond.Transform.Rotation -= gameTime.ElapsedGameTime.Nanoseconds * 0.0025f;
|
||||
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.N))
|
||||
{
|
||||
|
@ -217,6 +162,7 @@ public class Game1 : Game
|
|||
}
|
||||
static float physicsTimer = 0f;
|
||||
static float seconds = 0f;
|
||||
private GameObject gameObjectDiamond;
|
||||
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
|
@ -231,14 +177,16 @@ public class Game1 : Game
|
|||
|
||||
_spriteBatch.Begin(SpriteSortMode.Deferred, transformMatrix: cameraBehaviour.MatrixTransform);
|
||||
foreach (IGameObject gameObject in gameManager)
|
||||
{
|
||||
if (!gameObject.BehaviourController.TryGetBehaviour(out IDisplayable? displayable))
|
||||
continue;
|
||||
|
||||
if (gameObject.BehaviourController.TryGetBehaviour(out IDisplayable? displayable))
|
||||
displayable.Draw(_spriteBatch);
|
||||
}
|
||||
_spriteBatch.End();
|
||||
|
||||
_shapeBatch.Begin(cameraBehaviour.MatrixTransform);
|
||||
foreach (IGameObject gameObject in gameManager)
|
||||
if (gameObject.BehaviourController.TryGetBehaviour(out IDisplayableShape? displayableShape))
|
||||
displayableShape.Draw(_shapeBatch);
|
||||
_shapeBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue