feat: Circle Behaviour

This commit is contained in:
Syntriax 2024-01-25 18:52:47 +03:00
parent faf30b8227
commit 76484017e1
3 changed files with 66 additions and 24 deletions

2
Engine

@ -1 +1 @@
Subproject commit ed15238dcdc094453c697a8f83d9308f6702dc21 Subproject commit 9e1f38897fe9fbb229631dc5886bb0fe79e56427

View File

@ -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);
}
}

View File

@ -66,25 +66,41 @@ public class Game1 : Game
gameManager.Camera = cameraBehaviour; gameManager.Camera = cameraBehaviour;
IGameObject gameObjectDiamond = gameManager.InstantiateGameObject<GameObject>(); IGameObject gameObjectCircle = gameManager.InstantiateGameObject<GameObject>();
gameObjectDiamond.Name = "Diamond"; gameObjectCircle.Name = "Circle";
gameObjectDiamond.Transform.Position = new Vector2D(0f, 0f); gameObjectCircle.Transform.Position = new Vector2D(0f, -50f);
gameObjectDiamond.Transform.Scale = new Vector2D(100f, 100f); gameObjectCircle.Transform.Scale = new Vector2D(25f, 25f);
gameObjectDiamond.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>(); gameObjectCircle.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObjectDiamond.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f); gameObjectCircle.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
gameObjectDiamond.BehaviourController.AddBehaviour<RotatableBehaviour>(); gameObjectCircle.BehaviourController.AddBehaviour<CircleBehaviour>(new Circle(Vector2D.Zero, 1f));
gameObjectDiamond.BehaviourController.AddBehaviour<ShapeBehaviour>(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left])); engine.AddRigidBody(gameObjectCircle.BehaviourController.AddBehaviour<RigidBody2D>());
gameObjectDiamond.BehaviourController.AddBehaviour<ShapeAABBBehaviour>();
IGameObject gameObjectCircle2 = gameManager.InstantiateGameObject<GameObject>();
gameObjectCircle2.Name = "Circle2";
gameObjectCircle2.Transform.Position = new Vector2D(0f, 50f);
gameObjectCircle2.Transform.Scale = new Vector2D(25f, 25f);
gameObjectCircle2.BehaviourController.AddBehaviour<CircleBehaviour>(new Circle(Vector2D.Zero, 1f));
engine.AddRigidBody(gameObjectCircle2.BehaviourController.AddBehaviour<RigidBody2D>());
// IGameObject 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<RotatableBehaviour>();
// gameObjectDiamond.BehaviourController.AddBehaviour<ShapeBehaviour>(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left]));
// gameObjectDiamond.BehaviourController.AddBehaviour<ShapeAABBBehaviour>();
IGameObject gameObjectShape = gameManager.InstantiateGameObject<GameObject>(); // IGameObject gameObjectShape = gameManager.InstantiateGameObject<GameObject>();
gameObjectShape.Name = "Shape"; // gameObjectShape.Name = "Shape";
gameObjectShape.Transform.Position = new Vector2D(250f, 0f); // gameObjectShape.Transform.Position = new Vector2D(250f, 0f);
gameObjectShape.Transform.Scale = new Vector2D(100f, 100f); // gameObjectShape.Transform.Scale = new Vector2D(100f, 100f);
gameObjectShape.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>(); // gameObjectShape.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObjectShape.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f); // gameObjectShape.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
gameObjectShape.BehaviourController.AddBehaviour<RotatableBehaviour>(); // gameObjectShape.BehaviourController.AddBehaviour<RotatableBehaviour>();
gameObjectShape.BehaviourController.AddBehaviour<ShapeBehaviour>(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left])); // gameObjectShape.BehaviourController.AddBehaviour<ShapeBehaviour>(new Shape([Vector2D.Up, Vector2D.One, Vector2D.Right, Vector2D.Down, Vector2D.Zero, Vector2D.Left]));
// gameObjectShape.BehaviourController.AddBehaviour<ShapeAABBBehaviour>(); // gameObjectShape.BehaviourController.AddBehaviour<ShapeAABBBehaviour>();
} }
@ -160,12 +176,12 @@ public class Game1 : Game
} }
// while (physicsTimer + 0.01f < gameTime.TotalGameTime.TotalMilliseconds * .001f)//seconds) while (physicsTimer + 0.01f < gameTime.TotalGameTime.TotalMilliseconds * .001f)//seconds)
// { {
// Console.WriteLine($"Physics Timer: {physicsTimer}"); Console.WriteLine($"Physics Timer: {physicsTimer}");
// physicsTimer += 0.01f; physicsTimer += 0.01f;
// engine.Step(.01f); engine.Step(.01f);
// } }
gameManager.Update(gameTime.ToEngineTime()); gameManager.Update(gameTime.ToEngineTime());
base.Update(gameTime); base.Update(gameTime);
} }