From 46f589d3aa7dfa0344ab7a71e32dcd16f471b503 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Tue, 30 Jan 2024 14:35:24 +0300 Subject: [PATCH] feat: Camera Reset --- Game/Behaviours/CameraController.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Game/Behaviours/CameraController.cs b/Game/Behaviours/CameraController.cs index 641a51d..242f310 100644 --- a/Game/Behaviours/CameraController.cs +++ b/Game/Behaviours/CameraController.cs @@ -9,6 +9,8 @@ public class CameraController : BehaviourOverride private MonoGameCameraBehaviour cameraBehaviour = null!; private IButtonInputs buttonInputs = null!; + private float defaultZoomLevel = 1f; + protected override void OnFirstActiveFrame() { if (BehaviourController.TryGetBehaviour(out MonoGameCameraBehaviour? foundCameraBehaviour)) @@ -21,6 +23,7 @@ public class CameraController : BehaviourOverride buttonInputs ??= BehaviourController.AddBehaviour(); buttonInputs.RegisterOnPress(Keys.F, SwitchToFullScreen); + buttonInputs.RegisterOnPress(Keys.R, ResetCamera); } 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 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.Viewport = Game1.graphics.GraphicsDevice.Viewport; } + + private void ResetCamera(IButtonInputs inputs, Keys keys) + { + cameraBehaviour.Zoom = defaultZoomLevel; + Transform.Position = Vector2D.Zero; + Transform.Rotation = 0f; + } }