diff --git a/Game/Behaviours/CameraController.cs b/Game/Behaviours/CameraController.cs index 2b9ee60..32904fd 100644 --- a/Game/Behaviours/CameraController.cs +++ b/Game/Behaviours/CameraController.cs @@ -1,4 +1,5 @@ using Microsoft.Xna.Framework.Input; + using Syntriax.Engine.Core; using Syntriax.Engine.Input; @@ -41,20 +42,20 @@ public class CameraController : BehaviourOverride private void SwitchToFullScreen(IButtonInputs inputs, Keys keys) { - if (GamePong.graphics.IsFullScreen) + if (cameraBehaviour.Graphics.IsFullScreen) return; - GamePong.graphics.PreferMultiSampling = false; - GamePong.graphics.PreferredBackBufferWidth = GamePong.graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width; - GamePong.graphics.PreferredBackBufferHeight = GamePong.graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height; - GamePong.graphics.IsFullScreen = true; - GamePong.graphics.ApplyChanges(); + cameraBehaviour.Graphics.PreferMultiSampling = false; + cameraBehaviour.Graphics.PreferredBackBufferWidth = cameraBehaviour.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width; + cameraBehaviour.Graphics.PreferredBackBufferHeight = cameraBehaviour.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height; + cameraBehaviour.Graphics.IsFullScreen = true; + cameraBehaviour.Graphics.ApplyChanges(); float previousScreenSize = Math.Sqrt(Math.Sqr(cameraBehaviour.Viewport.Width) + Math.Sqr(cameraBehaviour.Viewport.Height)); - float currentScreenSize = Math.Sqrt(Math.Sqr(GamePong.graphics.GraphicsDevice.Viewport.Width) + Math.Sqr(GamePong.graphics.GraphicsDevice.Viewport.Height)); + float currentScreenSize = Math.Sqrt(Math.Sqr(cameraBehaviour.Graphics.GraphicsDevice.Viewport.Width) + Math.Sqr(cameraBehaviour.Graphics.GraphicsDevice.Viewport.Height)); defaultZoomLevel /= previousScreenSize / currentScreenSize; cameraBehaviour.Zoom /= previousScreenSize / currentScreenSize; - cameraBehaviour.Viewport = GamePong.graphics.GraphicsDevice.Viewport; + cameraBehaviour.Viewport = cameraBehaviour.Graphics.GraphicsDevice.Viewport; } private void ResetCamera(IButtonInputs inputs, Keys keys) diff --git a/Game/Behaviours/MonoGameCameraBehaviour.cs b/Game/Behaviours/MonoGameCameraBehaviour.cs index 69c8f3b..4a0501d 100644 --- a/Game/Behaviours/MonoGameCameraBehaviour.cs +++ b/Game/Behaviours/MonoGameCameraBehaviour.cs @@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics; using Syntriax.Engine.Core; namespace Pong.Behaviours; -public class MonoGameCameraBehaviour : BehaviourOverride +public class MonoGameCameraBehaviour(GraphicsDeviceManager Graphics) : BehaviourOverride { public System.Action? OnMatrixTransformChanged { get; set; } = null; public System.Action? OnViewportChanged { get; set; } = null; @@ -12,7 +12,7 @@ public class MonoGameCameraBehaviour : BehaviourOverride private Matrix _matrixTransform = Matrix.Identity; private Viewport _viewport = default; - + public GraphicsDeviceManager Graphics { get; } = Graphics; private float _zoom = 1f; public Matrix MatrixTransform @@ -69,7 +69,7 @@ public class MonoGameCameraBehaviour : BehaviourOverride } protected override void OnFirstActiveFrame() - => Viewport = GamePong.graphics.GraphicsDevice.Viewport; + => Viewport = Graphics.GraphicsDevice.Viewport; protected override void OnPreDraw() { diff --git a/Game/GamePong.cs b/Game/GamePong.cs index 2d05d8c..122e323 100644 --- a/Game/GamePong.cs +++ b/Game/GamePong.cs @@ -16,18 +16,20 @@ namespace Pong; public class GamePong : Game { - public static GraphicsDeviceManager graphics = null!; - public static IPhysicsEngine2D physicsEngine = null!; - public static SpriteBatch spriteBatch = null!; - public static ShapeBatch shapeBatch = null!; - public static GameManager gameManager = null!; + private readonly GraphicsDeviceManager graphics = null!; + private IPhysicsEngine2D physicsEngine = null!; + private SpriteBatch spriteBatch = null!; + private ShapeBatch shapeBatch = null!; + private GameManager gameManager = null!; private BehaviourCacher displayableCacher = null!; private BehaviourCacher displayableShapeCacher = null!; - private MonoGameCameraBehaviour cameraBehaviour = null!; + private PongManager pongManager = null!; + private float physicsTimer = 0f; + public GamePong() { graphics = new GraphicsDeviceManager(this) @@ -64,7 +66,7 @@ public class GamePong : Game IGameObject gameObjectCamera = gameManager.InstantiateGameObject().SetGameObject("Camera"); ; gameObjectCamera.BehaviourController.AddBehaviour(); - cameraBehaviour = gameObjectCamera.BehaviourController.AddBehaviour(); + cameraBehaviour = gameObjectCamera.BehaviourController.AddBehaviour(graphics); //////////////////////////////////////////////////////////////////////////////////// @@ -153,7 +155,6 @@ public class GamePong : Game } base.Update(gameTime); } - static float physicsTimer = 0f; protected override void Draw(GameTime gameTime) {