diff --git a/Engine b/Engine index 0766635..3817ebe 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit 07666359f26d4761914aac05d73fdbe0020b0b6a +Subproject commit 3817ebebfe3c3d328219656033f2518da6a59350 diff --git a/Game/Behaviours/MonoGameCameraBehaviour.cs b/Game/Behaviours/MonoGameCameraBehaviour.cs index f04f56f..69c8f3b 100644 --- a/Game/Behaviours/MonoGameCameraBehaviour.cs +++ b/Game/Behaviours/MonoGameCameraBehaviour.cs @@ -68,6 +68,9 @@ public class MonoGameCameraBehaviour : BehaviourOverride set => Transform.Rotation = value; } + protected override void OnFirstActiveFrame() + => Viewport = GamePong.graphics.GraphicsDevice.Viewport; + protected override void OnPreDraw() { MatrixTransform = diff --git a/Game/GamePong.cs b/Game/GamePong.cs index 362f5aa..402e30d 100644 --- a/Game/GamePong.cs +++ b/Game/GamePong.cs @@ -59,10 +59,9 @@ public class GamePong : Game shapeBatch = new ShapeBatch(GraphicsDevice, Content); SpriteFont spriteFont = Content.Load("UbuntuMono"); - IGameObject gameObjectCamera = gameManager.InstantiateGameObject(); - gameObjectCamera.Name = "Camera"; - gameObjectCamera.Transform.Position = Vector2D.Zero; + //////////////////////////////////////////////////////////////////////////////////// + IGameObject gameObjectCamera = gameManager.InstantiateGameObject().SetGameObject("Camera"); ; gameObjectCamera.BehaviourController.AddBehaviour(); cameraBehaviour = gameObjectCamera.BehaviourController.AddBehaviour(); @@ -70,16 +69,14 @@ public class GamePong : Game //////////////////////////////////////////////////////////////////////////////////// - IGameObject gameObjectPongManager = gameManager.InstantiateGameObject(); - gameObjectPongManager.Name = "Pong Game Manager"; + IGameObject gameObjectPongManager = gameManager.InstantiateGameObject().SetGameObject("Pong Game Manager"); pongManager = gameObjectPongManager.BehaviourController.AddBehaviour(5); //////////////////////////////////////////////////////////////////////////////////// - IGameObject gameObjectBall = gameManager.InstantiateGameObject(); - gameObjectBall.Name = "Ball"; - gameObjectBall.Transform.Position = new Vector2D(0, 0f); - gameObjectBall.Transform.Scale = new Vector2D(10f, 10f); + IGameObject gameObjectBall = gameManager.InstantiateGameObject().SetGameObject("Ball"); + gameObjectBall.Transform.SetTransform(position: new Vector2D(0, 0f), scale: new Vector2D(10f, 10f)); + gameObjectBall.BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)); PongBall ballBehaviour = gameObjectBall.BehaviourController.AddBehaviour(); RigidBody2D rigidBodyBall = gameObjectBall.BehaviourController.AddBehaviour(); @@ -87,20 +84,17 @@ public class GamePong : Game //////////////////////////////////////////////////////////////////////////////////// - IGameObject gameObjectLeftPaddle = gameManager.InstantiateGameObject(); - gameObjectLeftPaddle.Name = "Left Paddle"; - gameObjectLeftPaddle.Transform.Position = new Vector2D(-468f, 0f); - gameObjectLeftPaddle.Transform.Scale = new Vector2D(15f, 60f); + IGameObject gameObjectLeftPaddle = gameManager.InstantiateGameObject().SetGameObject("Left Paddle"); + gameObjectLeftPaddle.Transform.SetTransform(position: new Vector2D(-468f, 0f), scale: new Vector2D(15f, 60f)); + gameObjectLeftPaddle.BehaviourController.AddBehaviour(Keys.W, Keys.S, 228f, -228f, 400f); gameObjectLeftPaddle.BehaviourController.AddBehaviour(Shape.Box); RigidBody2D rigidBodyLeftPaddle = gameObjectLeftPaddle.BehaviourController.AddBehaviour(); rigidBodyLeftPaddle.IsStatic = true; engine.AddRigidBody(rigidBodyLeftPaddle); - IGameObject gameObjectRightPaddle = gameManager.InstantiateGameObject(); - gameObjectRightPaddle.Name = "Right Paddle"; - gameObjectRightPaddle.Transform.Position = new Vector2D(468f, 0f); - gameObjectRightPaddle.Transform.Scale = new Vector2D(15f, 60f); + IGameObject gameObjectRightPaddle = gameManager.InstantiateGameObject().SetGameObject("Right Paddle"); + gameObjectRightPaddle.Transform.SetTransform(position: new Vector2D(468f, 0f), scale: new Vector2D(15f, 60f)); gameObjectRightPaddle.BehaviourController.AddBehaviour(Keys.Up, Keys.Down, 228f, -228f, 400f); gameObjectRightPaddle.BehaviourController.AddBehaviour(Shape.Box); RigidBody2D rigidBodyRightPaddle = gameObjectRightPaddle.BehaviourController.AddBehaviour(); @@ -109,38 +103,30 @@ public class GamePong : Game //////////////////////////////////////////////////////////////////////////////////// - IGameObject gameObjectWallTop = gameManager.InstantiateGameObject(); - gameObjectWallTop.Name = "WallTop"; - gameObjectWallTop.Transform.Position = new Vector2D(0f, 308f); - gameObjectWallTop.Transform.Scale = new Vector2D(552f, 20f); + IGameObject gameObjectWallTop = gameManager.InstantiateGameObject().SetGameObject("Wall Top"); + gameObjectWallTop.Transform.SetTransform(position: new Vector2D(0f, 308f), scale: new Vector2D(552f, 20f)); gameObjectWallTop.BehaviourController.AddBehaviour(Shape.Box); RigidBody2D rigidBodyWallTop = gameObjectWallTop.BehaviourController.AddBehaviour(); rigidBodyWallTop.IsStatic = true; engine.AddRigidBody(rigidBodyWallTop); - IGameObject gameObjectWallBottom = gameManager.InstantiateGameObject(); - gameObjectWallBottom.Name = "WallBottom"; - gameObjectWallBottom.Transform.Position = new Vector2D(0f, -308f); - gameObjectWallBottom.Transform.Scale = new Vector2D(552f, 20f); + IGameObject gameObjectWallBottom = gameManager.InstantiateGameObject().SetGameObject("Wall Bottom"); + gameObjectWallBottom.Transform.SetTransform(position: new Vector2D(0f, -308f), scale: new Vector2D(552f, 20f)); gameObjectWallBottom.BehaviourController.AddBehaviour(Shape.Box); RigidBody2D rigidBodyWallBottom = gameObjectWallBottom.BehaviourController.AddBehaviour(); rigidBodyWallBottom.IsStatic = true; engine.AddRigidBody(rigidBodyWallBottom); - IGameObject gameObjectWallRight = gameManager.InstantiateGameObject(); - gameObjectWallRight.Name = "WallRight"; - gameObjectWallRight.Transform.Position = new Vector2D(532f, 0f); - gameObjectWallRight.Transform.Scale = new Vector2D(20f, 328f); + IGameObject gameObjectWallRight = gameManager.InstantiateGameObject().SetGameObject("Wall Right"); + gameObjectWallRight.Transform.SetTransform(position: new Vector2D(532f, 0f), scale: new Vector2D(20f, 328f)); gameObjectWallRight.BehaviourController.AddBehaviour((Action)pongManager.ScoreToLeft); gameObjectWallRight.BehaviourController.AddBehaviour(Shape.Box); RigidBody2D rigidBodyWallRight = gameObjectWallRight.BehaviourController.AddBehaviour(); rigidBodyWallRight.IsStatic = true; engine.AddRigidBody(rigidBodyWallRight); - IGameObject gameObjectWallLeft = gameManager.InstantiateGameObject(); - gameObjectWallLeft.Name = "WallLeft"; - gameObjectWallLeft.Transform.Position = new Vector2D(-532f, 0f); - gameObjectWallLeft.Transform.Scale = new Vector2D(20f, 328f); + IGameObject gameObjectWallLeft = gameManager.InstantiateGameObject().SetGameObject("Wall Left"); + gameObjectWallLeft.Transform.SetTransform(position: new Vector2D(-532f, 0f), scale: new Vector2D(20f, 328f)); gameObjectWallLeft.BehaviourController.AddBehaviour((Action)pongManager.ScoreToRight); gameObjectWallLeft.BehaviourController.AddBehaviour(Shape.Box); RigidBody2D rigidBodyWallLeft = gameObjectWallLeft.BehaviourController.AddBehaviour(); @@ -149,17 +135,14 @@ public class GamePong : Game //////////////////////////////////////////////////////////////////////////////////// - IGameObject gameObjectLeftScoreText = gameManager.InstantiateGameObject(); - gameObjectLeftScoreText.Name = "Score Left"; - gameObjectLeftScoreText.Transform.Position = new Vector2D(-250f, 250f); - gameObjectLeftScoreText.Transform.Scale = Vector2D.One * .25f; + IGameObject gameObjectLeftScoreText = gameManager.InstantiateGameObject().SetGameObject("Score Left"); + gameObjectLeftScoreText.Transform.SetTransform(position: new Vector2D(-250f, 250f), scale: Vector2D.One * .25f); PongTextBehaviour textBehaviourLeft = gameObjectLeftScoreText.BehaviourController.AddBehaviour(true); textBehaviourLeft.Font = spriteFont; textBehaviourLeft.Text = "0"; - IGameObject gameObjectRightScoreText = gameManager.InstantiateGameObject(); - gameObjectRightScoreText.Name = "Score Right"; - gameObjectRightScoreText.Transform.Position = new Vector2D(250f, 250f); - gameObjectRightScoreText.Transform.Scale = Vector2D.One * .25f; + + IGameObject gameObjectRightScoreText = gameManager.InstantiateGameObject().SetGameObject("Score Right"); + gameObjectRightScoreText.Transform.SetTransform(position: new Vector2D(250f, 250f), scale: Vector2D.One * .25f); PongTextBehaviour textBehaviourRight = gameObjectRightScoreText.BehaviourController.AddBehaviour(false); textBehaviourRight.Font = spriteFont; textBehaviourRight.Text = "0"; @@ -184,9 +167,6 @@ public class GamePong : Game { GraphicsDevice.Clear(new Color() { R = 32, G = 32, B = 32 }); - // gameManager.Camera.Position = gameObjectBall.Transform.Position; - // Console.WriteLine($"Pos: {gameManager.Camera.Position}"); - // TODO: Add your drawing code here gameManager.PreDraw();