refactor: Removed Static GamePong Fields
This commit is contained in:
parent
753c0031cd
commit
de2d5fb446
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
using Syntriax.Engine.Core;
|
using Syntriax.Engine.Core;
|
||||||
using Syntriax.Engine.Input;
|
using Syntriax.Engine.Input;
|
||||||
|
|
||||||
|
@ -41,20 +42,20 @@ public class CameraController : BehaviourOverride
|
||||||
|
|
||||||
private void SwitchToFullScreen(IButtonInputs<Keys> inputs, Keys keys)
|
private void SwitchToFullScreen(IButtonInputs<Keys> inputs, Keys keys)
|
||||||
{
|
{
|
||||||
if (GamePong.graphics.IsFullScreen)
|
if (cameraBehaviour.Graphics.IsFullScreen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GamePong.graphics.PreferMultiSampling = false;
|
cameraBehaviour.Graphics.PreferMultiSampling = false;
|
||||||
GamePong.graphics.PreferredBackBufferWidth = GamePong.graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width;
|
cameraBehaviour.Graphics.PreferredBackBufferWidth = cameraBehaviour.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width;
|
||||||
GamePong.graphics.PreferredBackBufferHeight = GamePong.graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height;
|
cameraBehaviour.Graphics.PreferredBackBufferHeight = cameraBehaviour.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height;
|
||||||
GamePong.graphics.IsFullScreen = true;
|
cameraBehaviour.Graphics.IsFullScreen = true;
|
||||||
GamePong.graphics.ApplyChanges();
|
cameraBehaviour.Graphics.ApplyChanges();
|
||||||
|
|
||||||
float previousScreenSize = Math.Sqrt(Math.Sqr(cameraBehaviour.Viewport.Width) + Math.Sqr(cameraBehaviour.Viewport.Height));
|
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;
|
defaultZoomLevel /= previousScreenSize / currentScreenSize;
|
||||||
cameraBehaviour.Zoom /= previousScreenSize / currentScreenSize;
|
cameraBehaviour.Zoom /= previousScreenSize / currentScreenSize;
|
||||||
cameraBehaviour.Viewport = GamePong.graphics.GraphicsDevice.Viewport;
|
cameraBehaviour.Viewport = cameraBehaviour.Graphics.GraphicsDevice.Viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetCamera(IButtonInputs<Keys> inputs, Keys keys)
|
private void ResetCamera(IButtonInputs<Keys> inputs, Keys keys)
|
||||||
|
|
|
@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
using Syntriax.Engine.Core;
|
using Syntriax.Engine.Core;
|
||||||
|
|
||||||
namespace Pong.Behaviours;
|
namespace Pong.Behaviours;
|
||||||
public class MonoGameCameraBehaviour : BehaviourOverride
|
public class MonoGameCameraBehaviour(GraphicsDeviceManager Graphics) : BehaviourOverride
|
||||||
{
|
{
|
||||||
public System.Action<MonoGameCameraBehaviour>? OnMatrixTransformChanged { get; set; } = null;
|
public System.Action<MonoGameCameraBehaviour>? OnMatrixTransformChanged { get; set; } = null;
|
||||||
public System.Action<MonoGameCameraBehaviour>? OnViewportChanged { get; set; } = null;
|
public System.Action<MonoGameCameraBehaviour>? OnViewportChanged { get; set; } = null;
|
||||||
|
@ -12,7 +12,7 @@ public class MonoGameCameraBehaviour : BehaviourOverride
|
||||||
private Matrix _matrixTransform = Matrix.Identity;
|
private Matrix _matrixTransform = Matrix.Identity;
|
||||||
|
|
||||||
private Viewport _viewport = default;
|
private Viewport _viewport = default;
|
||||||
|
public GraphicsDeviceManager Graphics { get; } = Graphics;
|
||||||
private float _zoom = 1f;
|
private float _zoom = 1f;
|
||||||
|
|
||||||
public Matrix MatrixTransform
|
public Matrix MatrixTransform
|
||||||
|
@ -69,7 +69,7 @@ public class MonoGameCameraBehaviour : BehaviourOverride
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFirstActiveFrame()
|
protected override void OnFirstActiveFrame()
|
||||||
=> Viewport = GamePong.graphics.GraphicsDevice.Viewport;
|
=> Viewport = Graphics.GraphicsDevice.Viewport;
|
||||||
|
|
||||||
protected override void OnPreDraw()
|
protected override void OnPreDraw()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,18 +16,20 @@ namespace Pong;
|
||||||
|
|
||||||
public class GamePong : Game
|
public class GamePong : Game
|
||||||
{
|
{
|
||||||
public static GraphicsDeviceManager graphics = null!;
|
private readonly GraphicsDeviceManager graphics = null!;
|
||||||
public static IPhysicsEngine2D physicsEngine = null!;
|
private IPhysicsEngine2D physicsEngine = null!;
|
||||||
public static SpriteBatch spriteBatch = null!;
|
private SpriteBatch spriteBatch = null!;
|
||||||
public static ShapeBatch shapeBatch = null!;
|
private ShapeBatch shapeBatch = null!;
|
||||||
public static GameManager gameManager = null!;
|
|
||||||
|
|
||||||
|
private GameManager gameManager = null!;
|
||||||
private BehaviourCacher<IDisplayable> displayableCacher = null!;
|
private BehaviourCacher<IDisplayable> displayableCacher = null!;
|
||||||
private BehaviourCacher<IDisplayableShape> displayableShapeCacher = null!;
|
private BehaviourCacher<IDisplayableShape> displayableShapeCacher = null!;
|
||||||
|
|
||||||
private MonoGameCameraBehaviour cameraBehaviour = null!;
|
private MonoGameCameraBehaviour cameraBehaviour = null!;
|
||||||
|
|
||||||
private PongManager pongManager = null!;
|
private PongManager pongManager = null!;
|
||||||
|
|
||||||
|
private float physicsTimer = 0f;
|
||||||
|
|
||||||
public GamePong()
|
public GamePong()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this)
|
graphics = new GraphicsDeviceManager(this)
|
||||||
|
@ -64,7 +66,7 @@ public class GamePong : Game
|
||||||
|
|
||||||
IGameObject gameObjectCamera = gameManager.InstantiateGameObject<GameObject>().SetGameObject("Camera"); ;
|
IGameObject gameObjectCamera = gameManager.InstantiateGameObject<GameObject>().SetGameObject("Camera"); ;
|
||||||
gameObjectCamera.BehaviourController.AddBehaviour<CameraController>();
|
gameObjectCamera.BehaviourController.AddBehaviour<CameraController>();
|
||||||
cameraBehaviour = gameObjectCamera.BehaviourController.AddBehaviour<MonoGameCameraBehaviour>();
|
cameraBehaviour = gameObjectCamera.BehaviourController.AddBehaviour<MonoGameCameraBehaviour>(graphics);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -153,7 +155,6 @@ public class GamePong : Game
|
||||||
}
|
}
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
static float physicsTimer = 0f;
|
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue