From 76484017e1b171f5a92f8b0f03f488d457f2e358 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Thu, 25 Jan 2024 18:52:47 +0300 Subject: [PATCH] feat: Circle Behaviour --- Engine | 2 +- Game/Behaviours/CircleBehaviour.cs | 26 +++++++++++++ Game/Game1.cs | 62 +++++++++++++++++++----------- 3 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 Game/Behaviours/CircleBehaviour.cs diff --git a/Engine b/Engine index ed15238..9e1f388 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit ed15238dcdc094453c697a8f83d9308f6702dc21 +Subproject commit 9e1f38897fe9fbb229631dc5886bb0fe79e56427 diff --git a/Game/Behaviours/CircleBehaviour.cs b/Game/Behaviours/CircleBehaviour.cs new file mode 100644 index 0000000..d5c7e67 --- /dev/null +++ b/Game/Behaviours/CircleBehaviour.cs @@ -0,0 +1,26 @@ +using Microsoft.Xna.Framework; + +using Apos.Shapes; + +using Syntriax.Engine.Core; +using Syntriax.Engine.Physics2D.Primitives; + +namespace Pong.Behaviours; + +public class CircleBehaviour : Syntriax.Engine.Physics2D.Collider2DCircleBehaviour, IDisplayableShape +{ + public CircleBehaviour(Circle circle) { this.CircleLocal = circle; } + public CircleBehaviour(Circle circle, float Thickness) { this.CircleLocal = circle; this.Thickness = Thickness; } + public CircleBehaviour(Circle circle, Color color) { this.CircleLocal = circle; Color = color; } + public CircleBehaviour(Circle circle, Color color, float Thickness) { this.CircleLocal = circle; this.Thickness = Thickness; Color = color; } + + public Color Color { get; set; } = Color.White; + public float Thickness { get; set; } = .5f; + + public void Draw(ShapeBatch shapeBatch) + { + Recalculate(); + + shapeBatch.BorderCircle(CircleWorld.Center.ToDisplayVector2(), CircleWorld.Radius, Color); + } +} diff --git a/Game/Game1.cs b/Game/Game1.cs index 08ea495..a103e9f 100644 --- a/Game/Game1.cs +++ b/Game/Game1.cs @@ -66,25 +66,41 @@ public class Game1 : Game gameManager.Camera = cameraBehaviour; - IGameObject gameObjectDiamond = gameManager.InstantiateGameObject(); - gameObjectDiamond.Name = "Diamond"; - gameObjectDiamond.Transform.Position = new Vector2D(0f, 0f); - gameObjectDiamond.Transform.Scale = new Vector2D(100f, 100f); - gameObjectDiamond.BehaviourController.AddBehaviour(); - gameObjectDiamond.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); - gameObjectDiamond.BehaviourController.AddBehaviour(); - gameObjectDiamond.BehaviourController.AddBehaviour(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left])); - gameObjectDiamond.BehaviourController.AddBehaviour(); + IGameObject gameObjectCircle = gameManager.InstantiateGameObject(); + gameObjectCircle.Name = "Circle"; + gameObjectCircle.Transform.Position = new Vector2D(0f, -50f); + gameObjectCircle.Transform.Scale = new Vector2D(25f, 25f); + gameObjectCircle.BehaviourController.AddBehaviour(); + gameObjectCircle.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); + gameObjectCircle.BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)); + engine.AddRigidBody(gameObjectCircle.BehaviourController.AddBehaviour()); + + IGameObject gameObjectCircle2 = gameManager.InstantiateGameObject(); + gameObjectCircle2.Name = "Circle2"; + gameObjectCircle2.Transform.Position = new Vector2D(0f, 50f); + gameObjectCircle2.Transform.Scale = new Vector2D(25f, 25f); + gameObjectCircle2.BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)); + engine.AddRigidBody(gameObjectCircle2.BehaviourController.AddBehaviour()); + + // IGameObject gameObjectDiamond = gameManager.InstantiateGameObject(); + // gameObjectDiamond.Name = "Diamond"; + // gameObjectDiamond.Transform.Position = new Vector2D(0f, 0f); + // gameObjectDiamond.Transform.Scale = new Vector2D(100f, 100f); + // gameObjectDiamond.BehaviourController.AddBehaviour(); + // gameObjectDiamond.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); + // gameObjectDiamond.BehaviourController.AddBehaviour(); + // gameObjectDiamond.BehaviourController.AddBehaviour(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left])); + // gameObjectDiamond.BehaviourController.AddBehaviour(); - IGameObject gameObjectShape = gameManager.InstantiateGameObject(); - gameObjectShape.Name = "Shape"; - gameObjectShape.Transform.Position = new Vector2D(250f, 0f); - gameObjectShape.Transform.Scale = new Vector2D(100f, 100f); - gameObjectShape.BehaviourController.AddBehaviour(); - gameObjectShape.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); - gameObjectShape.BehaviourController.AddBehaviour(); - gameObjectShape.BehaviourController.AddBehaviour(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left])); + // IGameObject gameObjectShape = gameManager.InstantiateGameObject(); + // gameObjectShape.Name = "Shape"; + // gameObjectShape.Transform.Position = new Vector2D(250f, 0f); + // gameObjectShape.Transform.Scale = new Vector2D(100f, 100f); + // gameObjectShape.BehaviourController.AddBehaviour(); + // gameObjectShape.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); + // gameObjectShape.BehaviourController.AddBehaviour(); + // gameObjectShape.BehaviourController.AddBehaviour(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left])); // gameObjectShape.BehaviourController.AddBehaviour(); } @@ -160,12 +176,12 @@ public class Game1 : Game } - // while (physicsTimer + 0.01f < gameTime.TotalGameTime.TotalMilliseconds * .001f)//seconds) - // { - // Console.WriteLine($"Physics Timer: {physicsTimer}"); - // physicsTimer += 0.01f; - // engine.Step(.01f); - // } + while (physicsTimer + 0.01f < gameTime.TotalGameTime.TotalMilliseconds * .001f)//seconds) + { + Console.WriteLine($"Physics Timer: {physicsTimer}"); + physicsTimer += 0.01f; + engine.Step(.01f); + } gameManager.Update(gameTime.ToEngineTime()); base.Update(gameTime); }