|
|
|
@@ -10,13 +10,14 @@ using Syntriax.Engine.Core;
|
|
|
|
|
using Syntriax.Engine.Core.Abstract;
|
|
|
|
|
using Syntriax.Engine.Physics2D;
|
|
|
|
|
using Syntriax.Engine.Physics2D.Primitives;
|
|
|
|
|
using Syntriax.Engine.Physics2D.Abstract;
|
|
|
|
|
|
|
|
|
|
namespace Pong;
|
|
|
|
|
|
|
|
|
|
public class Game1 : Game
|
|
|
|
|
{
|
|
|
|
|
private GraphicsDeviceManager _graphics = null!;
|
|
|
|
|
private PhysicsEngine2D engine;
|
|
|
|
|
private IPhysicsEngine2D engine = null!;
|
|
|
|
|
private SpriteBatch _spriteBatch = null!;
|
|
|
|
|
private ShapeBatch _shapeBatch = null!;
|
|
|
|
|
public static GameManager gameManager = null!;
|
|
|
|
@@ -26,7 +27,10 @@ public class Game1 : Game
|
|
|
|
|
|
|
|
|
|
public Game1()
|
|
|
|
|
{
|
|
|
|
|
engine = new PhysicsEngine2D();
|
|
|
|
|
engine = new PhysicsEngine2D
|
|
|
|
|
{
|
|
|
|
|
IterationCount = 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_graphics = new GraphicsDeviceManager(this)
|
|
|
|
|
{
|
|
|
|
@@ -65,72 +69,73 @@ public class Game1 : Game
|
|
|
|
|
cameraBehaviour.Viewport = GraphicsDevice.Viewport;
|
|
|
|
|
gameManager.Camera = cameraBehaviour;
|
|
|
|
|
|
|
|
|
|
IGameObject gameObjectBall = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectBall.Name = "Ball";
|
|
|
|
|
gameObjectBall.Transform.Position = new Vector2D(0, 0f);
|
|
|
|
|
gameObjectBall.Transform.Scale = new Vector2D(10f, 10f);
|
|
|
|
|
gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(Vector2D.One, 500f);
|
|
|
|
|
gameObjectBall.BehaviourController.AddBehaviour<CircleBehaviour>(new Circle(Vector2D.Zero, 1f));
|
|
|
|
|
engine.AddRigidBody(gameObjectBall.BehaviourController.AddBehaviour<RigidBody2D>());
|
|
|
|
|
|
|
|
|
|
// IGameObject gameObjectCircle = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
// gameObjectCircle.Name = "Circle";
|
|
|
|
|
// gameObjectCircle.Transform.Position = new Vector2D(0f, -50f);
|
|
|
|
|
// gameObjectCircle.Transform.Scale = new Vector2D(25f, 25f);
|
|
|
|
|
// gameObjectCircle.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
|
|
|
|
// gameObjectCircle.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
|
|
|
|
|
// gameObjectCircle.BehaviourController.AddBehaviour<CircleBehaviour>(new Circle(Vector2D.Zero, 1f));
|
|
|
|
|
// engine.AddRigidBody(gameObjectCircle.BehaviourController.AddBehaviour<RigidBody2D>());
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
IGameObject gameObjectCircle2 = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectCircle2.Name = "Circle2";
|
|
|
|
|
gameObjectCircle2.Transform.Position = new Vector2D(5f, 50f);
|
|
|
|
|
gameObjectCircle2.Transform.Scale = new Vector2D(25f, 25f);
|
|
|
|
|
gameObjectCircle2.BehaviourController.AddBehaviour<MovementMouseBehaviour>();
|
|
|
|
|
gameObjectCircle2.BehaviourController.AddBehaviour<CircleBehaviour>(new Circle(Vector2D.Zero, 1f));
|
|
|
|
|
engine.AddRigidBody(gameObjectCircle2.BehaviourController.AddBehaviour<RigidBody2D>());
|
|
|
|
|
IGameObject gameObjectLeftPaddle = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectLeftPaddle.Name = "Left Paddle";
|
|
|
|
|
gameObjectLeftPaddle.Transform.Position = new Vector2D(-468f, 0f);
|
|
|
|
|
gameObjectLeftPaddle.Transform.Scale = new Vector2D(15f, 60f);
|
|
|
|
|
gameObjectLeftPaddle.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 228f, -228f, 400f);
|
|
|
|
|
gameObjectLeftPaddle.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.Box);
|
|
|
|
|
RigidBody2D rigidBodyLeftPaddle = gameObjectLeftPaddle.BehaviourController.AddBehaviour<RigidBody2D>();
|
|
|
|
|
rigidBodyLeftPaddle.IsStatic = true;
|
|
|
|
|
engine.AddRigidBody(rigidBodyLeftPaddle);
|
|
|
|
|
|
|
|
|
|
IGameObject gameObjectDiamond = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectDiamond.Name = "Diamond";
|
|
|
|
|
gameObjectDiamond.Transform.Position = new Vector2D(-150f, -150f);
|
|
|
|
|
gameObjectDiamond.Transform.Scale = new Vector2D(50f, 50f);
|
|
|
|
|
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.One, Vector2D.Left]));
|
|
|
|
|
gameObjectDiamond.BehaviourController.AddBehaviour<ShapeAABBBehaviour>();
|
|
|
|
|
engine.AddRigidBody(gameObjectDiamond.BehaviourController.AddBehaviour<RigidBody2D>());
|
|
|
|
|
IGameObject gameObjectRightPaddle = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectRightPaddle.Name = "Right Paddle";
|
|
|
|
|
gameObjectRightPaddle.Transform.Position = new Vector2D(468f, 0f);
|
|
|
|
|
gameObjectRightPaddle.Transform.Scale = new Vector2D(15f, 60f);
|
|
|
|
|
gameObjectRightPaddle.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 228f, -228f, 400f);
|
|
|
|
|
gameObjectRightPaddle.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.Box);
|
|
|
|
|
RigidBody2D rigidBodyRightPaddle = gameObjectRightPaddle.BehaviourController.AddBehaviour<RigidBody2D>();
|
|
|
|
|
rigidBodyRightPaddle.IsStatic = true;
|
|
|
|
|
engine.AddRigidBody(rigidBodyRightPaddle);
|
|
|
|
|
|
|
|
|
|
IGameObject gameObjectBox = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectBox.Name = "Box";
|
|
|
|
|
gameObjectBox.Transform.Position = new Vector2D(150f, -150f);
|
|
|
|
|
gameObjectBox.Transform.Scale = new Vector2D(100f, 100f);
|
|
|
|
|
gameObjectBox.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
|
|
|
|
gameObjectBox.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
|
|
|
|
|
gameObjectBox.BehaviourController.AddBehaviour<RotatableBehaviour>();
|
|
|
|
|
gameObjectBox.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.Pentagon);
|
|
|
|
|
gameObjectBox.BehaviourController.AddBehaviour<ShapeAABBBehaviour>();
|
|
|
|
|
engine.AddRigidBody(gameObjectBox.BehaviourController.AddBehaviour<RigidBody2D>());
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
for (int i = 3; i < 10; i++)
|
|
|
|
|
{
|
|
|
|
|
IGameObject Test = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
Test.Name = i.ToString();
|
|
|
|
|
Test.Transform.Position = new Vector2D((i - 6) * 150, 0f);
|
|
|
|
|
Test.Transform.Scale = new Vector2D(75f, 75f);
|
|
|
|
|
Test.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
|
|
|
|
Test.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
|
|
|
|
|
Test.BehaviourController.AddBehaviour<RotatableBehaviour>();
|
|
|
|
|
Test.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.CreateNgon(i));
|
|
|
|
|
Test.BehaviourController.AddBehaviour<ShapeAABBBehaviour>();
|
|
|
|
|
RigidBody2D rigidBody = Test.BehaviourController.AddBehaviour<RigidBody2D>();
|
|
|
|
|
rigidBody.AngularVelocity = 90f;
|
|
|
|
|
engine.AddRigidBody(rigidBody);
|
|
|
|
|
}
|
|
|
|
|
IGameObject gameObjectWallTop = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectWallTop.Name = "WallTop";
|
|
|
|
|
gameObjectWallTop.Transform.Position = new Vector2D(0f, 298f);
|
|
|
|
|
gameObjectWallTop.Transform.Scale = new Vector2D(542f, 20f);
|
|
|
|
|
gameObjectWallTop.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.Box);
|
|
|
|
|
RigidBody2D rigidBodyWallTop = gameObjectWallTop.BehaviourController.AddBehaviour<RigidBody2D>();
|
|
|
|
|
rigidBodyWallTop.IsStatic = true;
|
|
|
|
|
engine.AddRigidBody(rigidBodyWallTop);
|
|
|
|
|
|
|
|
|
|
IGameObject gameObjectWallBottom = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectWallBottom.Name = "WallBottom";
|
|
|
|
|
gameObjectWallBottom.Transform.Position = new Vector2D(0f, -298f);
|
|
|
|
|
gameObjectWallBottom.Transform.Scale = new Vector2D(542f, 20f);
|
|
|
|
|
gameObjectWallBottom.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.Box);
|
|
|
|
|
RigidBody2D rigidBodyWallBottom = gameObjectWallBottom.BehaviourController.AddBehaviour<RigidBody2D>();
|
|
|
|
|
rigidBodyWallBottom.IsStatic = true;
|
|
|
|
|
engine.AddRigidBody(rigidBodyWallBottom);
|
|
|
|
|
|
|
|
|
|
// IGameObject gameObjectShape = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
// gameObjectShape.Name = "Shape";
|
|
|
|
|
// gameObjectShape.Transform.Position = new Vector2D(250f, 0f);
|
|
|
|
|
// gameObjectShape.Transform.Scale = new Vector2D(100f, 100f);
|
|
|
|
|
// gameObjectShape.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
|
|
|
|
// gameObjectShape.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
|
|
|
|
|
// 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<ShapeAABBBehaviour>();
|
|
|
|
|
IGameObject gameObjectWallRight = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectWallRight.Name = "WallRight";
|
|
|
|
|
gameObjectWallRight.Transform.Position = new Vector2D(522f, 0f);
|
|
|
|
|
gameObjectWallRight.Transform.Scale = new Vector2D(20f, 318f);
|
|
|
|
|
gameObjectWallRight.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.Box);
|
|
|
|
|
RigidBody2D rigidBodyWallRight = gameObjectWallRight.BehaviourController.AddBehaviour<RigidBody2D>();
|
|
|
|
|
rigidBodyWallRight.IsStatic = true;
|
|
|
|
|
engine.AddRigidBody(rigidBodyWallRight);
|
|
|
|
|
|
|
|
|
|
IGameObject gameObjectWallLeft = gameManager.InstantiateGameObject<GameObject>();
|
|
|
|
|
gameObjectWallLeft.Name = "WallLeft";
|
|
|
|
|
gameObjectWallLeft.Transform.Position = new Vector2D(-522f, 0f);
|
|
|
|
|
gameObjectWallLeft.Transform.Scale = new Vector2D(20f, 318f);
|
|
|
|
|
gameObjectWallLeft.BehaviourController.AddBehaviour<ShapeBehaviour>(Shape.Box);
|
|
|
|
|
RigidBody2D rigidBodyWallLeft = gameObjectWallLeft.BehaviourController.AddBehaviour<RigidBody2D>();
|
|
|
|
|
rigidBodyWallLeft.IsStatic = true;
|
|
|
|
|
engine.AddRigidBody(rigidBodyWallLeft);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
|
|
@@ -204,14 +209,13 @@ public class Game1 : Game
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gameManager.Update(gameTime.ToEngineTime());
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
static float physicsTimer = 0f;
|
|
|
|
|