feat: Camera Reset

This commit is contained in:
Syntriax 2024-01-30 14:35:24 +03:00
parent b7d49e41c3
commit 46f589d3aa
1 changed files with 11 additions and 0 deletions

View File

@ -9,6 +9,8 @@ public class CameraController : BehaviourOverride
private MonoGameCameraBehaviour cameraBehaviour = null!; private MonoGameCameraBehaviour cameraBehaviour = null!;
private IButtonInputs<Keys> buttonInputs = null!; private IButtonInputs<Keys> buttonInputs = null!;
private float defaultZoomLevel = 1f;
protected override void OnFirstActiveFrame() protected override void OnFirstActiveFrame()
{ {
if (BehaviourController.TryGetBehaviour(out MonoGameCameraBehaviour? foundCameraBehaviour)) if (BehaviourController.TryGetBehaviour(out MonoGameCameraBehaviour? foundCameraBehaviour))
@ -21,6 +23,7 @@ public class CameraController : BehaviourOverride
buttonInputs ??= BehaviourController.AddBehaviour<KeyboardInputsBehaviour>(); buttonInputs ??= BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
buttonInputs.RegisterOnPress(Keys.F, SwitchToFullScreen); buttonInputs.RegisterOnPress(Keys.F, SwitchToFullScreen);
buttonInputs.RegisterOnPress(Keys.R, ResetCamera);
} }
protected override void OnUpdate() protected override void OnUpdate()
@ -49,7 +52,15 @@ public class CameraController : BehaviourOverride
float previousScreenSize = Math.Sqrt(Math.Pow(cameraBehaviour.Viewport.Width, 2f) + Math.Pow(cameraBehaviour.Viewport.Height, 2f)); float previousScreenSize = Math.Sqrt(Math.Pow(cameraBehaviour.Viewport.Width, 2f) + Math.Pow(cameraBehaviour.Viewport.Height, 2f));
float currentScreenSize = Math.Sqrt(Math.Pow(Game1.graphics.GraphicsDevice.Viewport.Width, 2f) + Math.Pow(Game1.graphics.GraphicsDevice.Viewport.Height, 2f)); float currentScreenSize = Math.Sqrt(Math.Pow(Game1.graphics.GraphicsDevice.Viewport.Width, 2f) + Math.Pow(Game1.graphics.GraphicsDevice.Viewport.Height, 2f));
defaultZoomLevel /= previousScreenSize / currentScreenSize;
cameraBehaviour.Zoom /= previousScreenSize / currentScreenSize; cameraBehaviour.Zoom /= previousScreenSize / currentScreenSize;
cameraBehaviour.Viewport = Game1.graphics.GraphicsDevice.Viewport; cameraBehaviour.Viewport = Game1.graphics.GraphicsDevice.Viewport;
} }
private void ResetCamera(IButtonInputs<Keys> inputs, Keys keys)
{
cameraBehaviour.Zoom = defaultZoomLevel;
Transform.Position = Vector2D.Zero;
Transform.Rotation = 0f;
}
} }