diff --git a/Scenes/Levels/Systems/CameraSystem.cs b/Scenes/Levels/Systems/CameraSystem.cs index df7eb04..2269f6e 100644 --- a/Scenes/Levels/Systems/CameraSystem.cs +++ b/Scenes/Levels/Systems/CameraSystem.cs @@ -3,6 +3,7 @@ using NovemberPirates.Components; using NovemberPirates.Systems; using Raylib_CsLo; +using System.Numerics; namespace NovemberPirates.Scenes.Levels.Systems { @@ -12,6 +13,8 @@ public CameraSystem() { } + private float CameraSpeed = 3f; + internal override void Update(World world) { var query = new QueryDescription().WithAll(); @@ -23,16 +26,16 @@ internal override void Update(World world) world.Query(in query, (entity) => { - var targetPos = entity.Get().Position; - - var xdiff = 0; + var shipSprite = entity.Get(); + var targetPos = shipSprite.Position + RayMath.Vector2Rotate(new Vector2(0, -100), shipSprite.RotationAsRadians); + var xdiff = 0; var ydiff = 0; var x = targetPos.X - xdiff; if (x < LeftEdge) { x = LeftEdge; - } + } else if (x > RightEdge) { x = RightEdge; @@ -46,9 +49,12 @@ internal override void Update(World world) { y = BottomEdge; } + var direction = new Vector2(x, y) - NovemberPiratesEngine.Instance.Camera.target; + var currentPos = NovemberPiratesEngine.Instance.Camera.target; + var futurePos = currentPos + (direction * CameraSpeed * Raylib.GetFrameTime()); - NovemberPiratesEngine.Instance.Camera.target.X = x; - NovemberPiratesEngine.Instance.Camera.target.Y = y; + NovemberPiratesEngine.Instance.Camera.target.X = futurePos.X; + NovemberPiratesEngine.Instance.Camera.target.Y = futurePos.Y; }); } }