From a2da54172e9d5ffce917f83faeaddd8c5478f74e Mon Sep 17 00:00:00 2001 From: Syntriax Date: Fri, 24 Nov 2023 17:48:50 +0300 Subject: [PATCH] chore: Don't Ask I can't believe this seems to work xD I can recycle components and this would allow me to maybe even Pool the components! --- Engine | 2 +- Game/Game1.cs | 65 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/Engine b/Engine index d60537f..d75bae8 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit d60537f9406ae3615c7cdcd6f986cf368fa77cfb +Subproject commit d75bae802abfd044457d3bd9cfc6d9e5faad4656 diff --git a/Game/Game1.cs b/Game/Game1.cs index aff900a..4e0dd45 100644 --- a/Game/Game1.cs +++ b/Game/Game1.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using System; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Pong.Behaviours; @@ -14,6 +15,8 @@ public class Game1 : Game private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; private GameManager gameManager = null!; + private GameObject gameObjectLeft; + private GameObject gameObjectRight; public Game1() { @@ -37,24 +40,22 @@ public class Game1 : Game _spriteBatch = new SpriteBatch(GraphicsDevice); Sprite sprite = new Sprite() { Texture2D = Content.Load("Sprites/Pixel") }; - { - IGameObject gameObject = gameManager.InstantiateGameObject(); - gameObject.Name = "Left"; - gameObject.Transform.Position = new Vector2(Window.ClientBounds.Width * .1f, Window.ClientBounds.Height * .5f); - gameObject.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); - gameObject.BehaviourController.AddBehaviour(); - gameObject.BehaviourController.AddBehaviour(Keys.S, Keys.W, 200f); - gameObject.BehaviourController.AddBehaviour().Assign(sprite); - } - { - IGameObject gameObject = gameManager.InstantiateGameObject(); - gameObject.Name = "Right"; - gameObject.Transform.Position = new Vector2(Window.ClientBounds.Width * .9f, Window.ClientBounds.Height * .5f); - gameObject.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); - gameObject.BehaviourController.AddBehaviour(); - gameObject.BehaviourController.AddBehaviour(Keys.Down, Keys.Up, 200f); - gameObject.BehaviourController.AddBehaviour().Assign(sprite); - } + gameObjectLeft = gameManager.InstantiateGameObject(); + gameObjectLeft.Name = "Left"; + gameObjectLeft.Transform.Position = new Vector2(Window.ClientBounds.Width * .1f, Window.ClientBounds.Height * .5f); + gameObjectLeft.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); + gameObjectLeft.BehaviourController.AddBehaviour(); + gameObjectLeft.BehaviourController.AddBehaviour(Keys.S, Keys.W, 200f); + gameObjectLeft.BehaviourController.AddBehaviour().Assign(sprite); + + gameObjectRight = gameManager.InstantiateGameObject(); + gameObjectRight.Name = "Right"; + gameObjectRight.Transform.Position = new Vector2(Window.ClientBounds.Width * .9f, Window.ClientBounds.Height * .5f); + gameObjectRight.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); + gameObjectRight.BehaviourController.AddBehaviour(); + gameObjectRight.BehaviourController.AddBehaviour(Keys.Down, Keys.Up, 200f); + gameObjectRight.BehaviourController.AddBehaviour().Assign(sprite); + // TODO: use this.Content to load your game content here } @@ -62,6 +63,7 @@ public class Game1 : Game { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); + if (Keyboard.GetState().IsKeyDown(Keys.F)) { _graphics.PreferMultiSampling = false; @@ -71,6 +73,31 @@ public class Game1 : Game _graphics.ApplyChanges(); } + if (Keyboard.GetState().IsKeyDown(Keys.H)) + { + gameManager.RemoveGameObject(gameObjectLeft); + gameManager.RemoveGameObject(gameObjectRight); + + IBehaviourController lbc = gameObjectLeft.BehaviourController; + IBehaviourController rbc = gameObjectRight.BehaviourController; + + Console.WriteLine($"LeftBehaviourController: {lbc.GameObject.Name}"); + Console.WriteLine($"RightBehaviourController: {rbc.GameObject.Name}"); + + Console.WriteLine($"gameObjectLeft.Assign(rbc): {gameObjectLeft.Assign(rbc)}"); + Console.WriteLine($"gameObjectRight.Assign(lbc): {gameObjectRight.Assign(lbc)}"); + + Console.WriteLine($"lbc.Assign(gameObjectRight): {lbc.Assign(gameObjectRight)}"); + Console.WriteLine($"rbc.Assign(gameObjectLeft): {rbc.Assign(gameObjectLeft)}"); + + gameManager.RegisterGameObject(gameObjectLeft); + gameManager.RegisterGameObject(gameObjectRight); + + Console.WriteLine($"LeftBehaviourController: {lbc.GameObject.Name}"); + Console.WriteLine($"RightBehaviourController: {rbc.GameObject.Name}"); + Console.WriteLine($"//////////////////////////////////////////////////"); + } + // TODO: Add your update logic here gameManager.Update(gameTime);