This commit is contained in:
Syntriax 2023-12-06 17:45:00 +03:00
parent 94897a06a3
commit 03ba4878c0
1 changed files with 11 additions and 3 deletions

View File

@ -46,7 +46,7 @@ public class Game1 : Game
protected override void LoadContent() protected override void LoadContent()
{ {
engine = new PhysicsEngine2D() { IterationCount = 100 }; engine = new PhysicsEngine2D();
_spriteBatch = new SpriteBatch(GraphicsDevice); _spriteBatch = new SpriteBatch(GraphicsDevice);
spriteBox = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") }; spriteBox = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") };
@ -67,6 +67,14 @@ public class Game1 : Game
gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2(.1f, .01f), 500f); gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2(.1f, .01f), 500f);
gameObjectBall.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBall); gameObjectBall.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBall);
gameObjectBall.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2.One * 512f * .5f, Vector2.One * 512f * .5f); gameObjectBall.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2.One * 512f * .5f, Vector2.One * 512f * .5f);
gameObjectBall = gameManager.InstantiateGameObject<GameObject>();
gameObjectBall.Name = "Ball";
gameObjectBall.Transform.Position = Vector2.UnitY * 30f;
gameObjectBall.Transform.Scale = new Vector2(1f / 51.2f, 1f / 51.2f);
engine.AddRigidBody(gameObjectBall.BehaviourController.AddBehaviour<RigidBody2D>());
gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2(.1f, .01f), 500f);
gameObjectBall.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBall);
gameObjectBall.BehaviourController.AddBehaviour<Collider2DAABBBehaviour>().AABBLocal = new AABB(-Vector2.One * 512f * .5f, Vector2.One * 512f * .5f);
IGameObject gameObjectLeft = gameManager.InstantiateGameObject<GameObject>(); IGameObject gameObjectLeft = gameManager.InstantiateGameObject<GameObject>();
gameObjectLeft.Name = "Left"; gameObjectLeft.Name = "Left";
@ -175,7 +183,7 @@ public class Game1 : Game
} }
if (Keyboard.GetState().IsKeyDown(Keys.Space)) if (Keyboard.GetState().IsKeyDown(Keys.Space))
{ {
seconds += gameTime.ElapsedGameTime.Milliseconds * .0025f; seconds += gameTime.ElapsedGameTime.Milliseconds * .005f;
while (physicsTimer + 0.01f < seconds) while (physicsTimer + 0.01f < seconds)
{ {
Console.WriteLine($"Physics Timer: {physicsTimer}"); Console.WriteLine($"Physics Timer: {physicsTimer}");
@ -185,7 +193,7 @@ public class Game1 : Game
} }
if (Keyboard.GetState().IsKeyDown(Keys.B)) if (Keyboard.GetState().IsKeyDown(Keys.B))
{ {
seconds -= gameTime.ElapsedGameTime.Milliseconds * .0025f; seconds -= gameTime.ElapsedGameTime.Milliseconds * .005f;
while (physicsTimer - 0.01f > seconds) while (physicsTimer - 0.01f > seconds)
{ {
Console.WriteLine($"Physics Timer: {physicsTimer}"); Console.WriteLine($"Physics Timer: {physicsTimer}");