From ef08eedc349a1cffb760d4f796fe79169027de2a Mon Sep 17 00:00:00 2001 From: Syntriax Date: Fri, 26 Jan 2024 19:21:26 +0300 Subject: [PATCH] feat: Test Shapes Scene --- Engine | 2 +- Game/Behaviours/ShapeAABBBehaviour.cs | 10 ++++- Game/Game1.cs | 62 +++++++++++++++++++-------- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/Engine b/Engine index ceebe21..85bad95 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit ceebe210417e52abf6d904ae603d82263b658599 +Subproject commit 85bad951ff9802d1b8c0a00e23f11914b5acd20d diff --git a/Game/Behaviours/ShapeAABBBehaviour.cs b/Game/Behaviours/ShapeAABBBehaviour.cs index 23f2b21..635ef75 100644 --- a/Game/Behaviours/ShapeAABBBehaviour.cs +++ b/Game/Behaviours/ShapeAABBBehaviour.cs @@ -3,8 +3,9 @@ using Microsoft.Xna.Framework; using Apos.Shapes; using Syntriax.Engine.Core; -using Syntriax.Engine.Physics2D.Primitives; +using Syntriax.Engine.Input; using Syntriax.Engine.Physics2D.Abstract; +using Syntriax.Engine.Physics2D.Primitives; namespace Pong.Behaviours; @@ -19,14 +20,21 @@ public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape public Color Color { get; set; } = Color.White; public float Thickness { get; set; } = .5f; + public bool display = true; protected override void OnFirstActiveFrame() { BehaviourController.TryGetBehaviour(out shapeCollider); + + if (BehaviourController.TryGetBehaviour(out IButtonInputs? keys)) + keys.RegisterOnPress(Microsoft.Xna.Framework.Input.Keys.D, (_1, _2) => display = !display); } public void Draw(ShapeBatch shapeBatch) { + if (!display) + return; + if (shapeCollider is null) return; diff --git a/Game/Game1.cs b/Game/Game1.cs index 05a7b27..9515341 100644 --- a/Game/Game1.cs +++ b/Game/Game1.cs @@ -66,14 +66,14 @@ public class Game1 : Game gameManager.Camera = cameraBehaviour; - 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 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"; @@ -83,15 +83,43 @@ public class Game1 : Game 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 gameObjectDiamond = gameManager.InstantiateGameObject(); + gameObjectDiamond.Name = "Diamond"; + gameObjectDiamond.Transform.Position = new Vector2D(-150f, -150f); + gameObjectDiamond.Transform.Scale = new Vector2D(50f, 50f); + 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.One, Vector2D.Left])); + gameObjectDiamond.BehaviourController.AddBehaviour(); + engine.AddRigidBody(gameObjectDiamond.BehaviourController.AddBehaviour()); + + IGameObject gameObjectBox = gameManager.InstantiateGameObject(); + gameObjectBox.Name = "Box"; + gameObjectBox.Transform.Position = new Vector2D(150f, -150f); + gameObjectBox.Transform.Scale = new Vector2D(100f, 100f); + gameObjectBox.BehaviourController.AddBehaviour(); + gameObjectBox.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); + gameObjectBox.BehaviourController.AddBehaviour(); + gameObjectBox.BehaviourController.AddBehaviour(Shape.Pentagon); + gameObjectBox.BehaviourController.AddBehaviour(); + engine.AddRigidBody(gameObjectBox.BehaviourController.AddBehaviour()); + + for (int i = 3; i < 10; i++) + { + IGameObject Test = gameManager.InstantiateGameObject(); + Test.Name = i.ToString(); + Test.Transform.Position = new Vector2D((i - 6) * 150, 0f); + Test.Transform.Scale = new Vector2D(75f, 75f); + Test.BehaviourController.AddBehaviour(); + Test.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); + Test.BehaviourController.AddBehaviour(); + Test.BehaviourController.AddBehaviour(Shape.CreateNgon(i)); + Test.BehaviourController.AddBehaviour(); + RigidBody2D rigidBody = Test.BehaviourController.AddBehaviour(); + rigidBody.AngularVelocity = 90f; + engine.AddRigidBody(rigidBody); + } // IGameObject gameObjectShape = gameManager.InstantiateGameObject();