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:
parent
0ec68e6b1a
commit
a2da54172e
2
Engine
2
Engine
|
@ -1 +1 @@
|
|||
Subproject commit d60537f9406ae3615c7cdcd6f986cf368fa77cfb
|
||||
Subproject commit d75bae802abfd044457d3bd9cfc6d9e5faad4656
|
|
@ -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<Texture2D>("Sprites/Pixel") };
|
||||
{
|
||||
IGameObject gameObject = gameManager.InstantiateGameObject<GameObject>();
|
||||
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<KeyboardInputsBehaviour>();
|
||||
gameObject.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.S, Keys.W, 200f);
|
||||
gameObject.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().Assign(sprite);
|
||||
}
|
||||
{
|
||||
IGameObject gameObject = gameManager.InstantiateGameObject<GameObject>();
|
||||
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<KeyboardInputsBehaviour>();
|
||||
gameObject.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.Down, Keys.Up, 200f);
|
||||
gameObject.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().Assign(sprite);
|
||||
}
|
||||
gameObjectLeft = gameManager.InstantiateGameObject<GameObject>();
|
||||
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<KeyboardInputsBehaviour>();
|
||||
gameObjectLeft.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.S, Keys.W, 200f);
|
||||
gameObjectLeft.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().Assign(sprite);
|
||||
|
||||
gameObjectRight = gameManager.InstantiateGameObject<GameObject>();
|
||||
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<KeyboardInputsBehaviour>();
|
||||
gameObjectRight.BehaviourController.AddBehaviour<MovementBehaviour>(Keys.Down, Keys.Up, 200f);
|
||||
gameObjectRight.BehaviourController.AddBehaviour<DrawableSpriteBehaviour>().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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue