diff --git a/Engine b/Engine index 499f875..fe0173b 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit 499f87590335238a0c8b04a29ccd825dcfd55735 +Subproject commit fe0173b091a00e02dd0ebe59f6678228e0d6f540 diff --git a/Shared/Behaviours/CameraController.cs b/Shared/Behaviours/CameraController.cs index f0e8c03..e46bea6 100644 --- a/Shared/Behaviours/CameraController.cs +++ b/Shared/Behaviours/CameraController.cs @@ -53,11 +53,11 @@ public class CameraController : Behaviour, IFirstFrameUpdate, IUpdate cameraBehaviour.Graphics.IsFullScreen = true; 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.X) + Math.Sqr(cameraBehaviour.Viewport.Y)); 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 = cameraBehaviour.Graphics.GraphicsDevice.Viewport; + cameraBehaviour.Viewport = new(cameraBehaviour.Graphics.GraphicsDevice.Viewport.Width, cameraBehaviour.Graphics.GraphicsDevice.Viewport.Height); } private void ResetCamera(IButtonInputs sender, IButtonInputs.ButtonCallbackArguments args) diff --git a/Shared/Behaviours/Label.cs b/Shared/Behaviours/Label.cs index 9e82214..ee1749f 100644 --- a/Shared/Behaviours/Label.cs +++ b/Shared/Behaviours/Label.cs @@ -8,24 +8,49 @@ namespace Pong.Behaviours; public class Label : Behaviour2D, IDrawableSprite, ILoadContent { - public SpriteFont? Font { get; set; } = null; public ColorRGBA Color { get; set; } = new ColorRGBA(255, 255, 255, 255); - public int Size { get; set; } = 16; - public string Text { get; set; } = string.Empty; - public void Draw(ISpriteBatch spriteBatch) + public SpriteFont? Font { - if (Font is null) - return; + get => field; + set + { + field = value; + UpdateTextSize(); + } + } = null; - spriteBatch.DrawString(Font, Text, Transform.Position, Color.ToPreMultipliedColor(), Transform.Rotation, Vector2D.One * .5f, Transform.Scale.Magnitude, SpriteEffects.None, 0f); - } + public string Text + { + get => field; + set + { + field = value; + UpdateTextSize(); + } + } = string.Empty; + + private Vector2D textSize = Vector2D.Zero; public void LoadContent(ContentManager content) { Font ??= content.Load("UbuntuMono"); } + public void Draw(ISpriteBatch spriteBatch) + { + if (Font is null) + return; + + spriteBatch.DrawString(Font, Text, Transform.Position, Color.ToPreMultipliedColor(), Transform.Rotation, textSize * .5f, Transform.Scale.Magnitude, SpriteEffects.FlipVertically, 0f); + } + + private void UpdateTextSize() + { + if (Font is not null) + textSize = Font.MeasureString(Text).ToVector2D(); + } + public Label() { } public Label(SpriteFont font) => Font = font; } diff --git a/Shared/PongUniverse.cs b/Shared/PongUniverse.cs index f426a8c..4086709 100644 --- a/Shared/PongUniverse.cs +++ b/Shared/PongUniverse.cs @@ -38,11 +38,11 @@ public static class PongUniverse //////////////////////////////////////////////////////////////////////////////////// universe.InstantiateUniverseObject().SetUniverseObject("Score Left") - .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-250f, 250f), scale: Vector2D.One * .25f) + .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-250f, 125f), scale: Vector2D.One * .25f) .BehaviourController.AddBehaviour(true); universe.InstantiateUniverseObject().SetUniverseObject("Score Right") - .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(250f, 250f), scale: Vector2D.One * .25f) + .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(250f, 125f), scale: Vector2D.One * .25f) .BehaviourController.AddBehaviour(false); return universe; @@ -72,7 +72,7 @@ public static class PongUniverse universe.InstantiateUniverseObject().SetUniverseObject("Pong Game Starter", parent: pongManager.UniverseObject) .BehaviourController.AddBehaviour() - .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-24, 250f), scale: Vector2D.One * .5f) + .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-24, 125f), scale: Vector2D.One * .5f) .BehaviourController.AddBehaviour