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!
This commit is contained in:
Syntriax 2023-11-24 17:48:50 +03:00
parent 0ec68e6b1a
commit a2da54172e
2 changed files with 47 additions and 20 deletions

2
Engine

@ -1 +1 @@
Subproject commit d60537f9406ae3615c7cdcd6f986cf368fa77cfb Subproject commit d75bae802abfd044457d3bd9cfc6d9e5faad4656

View File

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework; using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Pong.Behaviours; using Pong.Behaviours;
@ -14,6 +15,8 @@ public class Game1 : Game
private GraphicsDeviceManager _graphics; private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch; private SpriteBatch _spriteBatch;
private GameManager gameManager = null!; private GameManager gameManager = null!;
private GameObject gameObjectLeft;
private GameObject gameObjectRight;
public Game1() public Game1()
{ {
@ -37,24 +40,22 @@ public class Game1 : Game
_spriteBatch = new SpriteBatch(GraphicsDevice); _spriteBatch = new SpriteBatch(GraphicsDevice);
Sprite sprite = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") }; Sprite sprite = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") };
{ gameObjectLeft = gameManager.InstantiateGameObject<GameObject>();
IGameObject gameObject = gameManager.InstantiateGameObject<GameObject>(); gameObjectLeft.Name = "Left";
gameObject.Name = "Left"; gameObjectLeft.Transform.Position = new Vector2(Window.ClientBounds.Width * .1f, Window.ClientBounds.Height * .5f);
gameObject.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);
gameObject.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); gameObjectLeft.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObject.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>(); gameObjectLeft.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.S, Keys.W, 200f);
gameObject.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.S, Keys.W, 200f); gameObjectLeft.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().Assign(sprite);
gameObject.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().Assign(sprite);
} gameObjectRight = gameManager.InstantiateGameObject<GameObject>();
{ gameObjectRight.Name = "Right";
IGameObject gameObject = gameManager.InstantiateGameObject<GameObject>(); gameObjectRight.Transform.Position = new Vector2(Window.ClientBounds.Width * .9f, Window.ClientBounds.Height * .5f);
gameObject.Name = "Right"; gameObjectRight.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f);
gameObject.Transform.Position = new Vector2(Window.ClientBounds.Width * .9f, Window.ClientBounds.Height * .5f); gameObjectRight.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObject.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); gameObjectRight.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.Down, Keys.Up, 200f);
gameObject.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>(); gameObjectRight.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().Assign(sprite);
gameObject.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.Down, Keys.Up, 200f);
gameObject.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().Assign(sprite);
}
// TODO: use this.Content to load your game content here // 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)) if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit(); Exit();
if (Keyboard.GetState().IsKeyDown(Keys.F)) if (Keyboard.GetState().IsKeyDown(Keys.F))
{ {
_graphics.PreferMultiSampling = false; _graphics.PreferMultiSampling = false;
@ -71,6 +73,31 @@ public class Game1 : Game
_graphics.ApplyChanges(); _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 // TODO: Add your update logic here
gameManager.Update(gameTime); gameManager.Update(gameTime);