From 37c679b704add5af74e1addcd61fe14f86b46f35 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 10 Mar 2020 14:38:08 -0400 Subject: [PATCH] move Camera into World --- Shared/SneakGame.cs | 5 +---- Shared/World.cs | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Shared/SneakGame.cs b/Shared/SneakGame.cs index b3656b2..d593544 100644 --- a/Shared/SneakGame.cs +++ b/Shared/SneakGame.cs @@ -23,7 +23,6 @@ namespace SemiColinGames { Scene scene; World world; - Camera camera = new Camera(); public SneakGame() { Debug.WriteLine("MonoGame platform: " + PlatformInfo.MonoGamePlatform + @@ -64,11 +63,10 @@ namespace SemiColinGames { } private void LoadLevel() { - camera = new Camera(); world?.Dispose(); world = new World(GraphicsDevice, Content.LoadString("levels/demo.json")); scene?.Dispose(); - scene = new Scene(GraphicsDevice, camera); + scene = new Scene(GraphicsDevice, world.Camera); GC.Collect(); GC.WaitForPendingFinalizers(); @@ -112,7 +110,6 @@ namespace SemiColinGames { float modelTime = (float) gameTime.ElapsedGameTime.TotalSeconds; Clock.AddModelTime(modelTime); world.Update(modelTime, input); - camera.Update(world.Player.Position, world.Width); } base.Update(gameTime); diff --git a/Shared/World.cs b/Shared/World.cs index 8a5723b..9c15b8f 100644 --- a/Shared/World.cs +++ b/Shared/World.cs @@ -22,6 +22,7 @@ namespace SemiColinGames { public Player Player { get; private set; } public AABB[] CollisionTargets { get; } public LinesOfSight LinesOfSight { get; private set; } + public Camera Camera { get; } // Size of World in pixels. public int Width { @@ -33,6 +34,7 @@ namespace SemiColinGames { } public World(GraphicsDevice graphics, string json) { + Camera = new Camera(); LinesOfSight = new LinesOfSight(graphics); JObject root = JObject.Parse(json); @@ -162,6 +164,7 @@ namespace SemiColinGames { Reset(); } LinesOfSight.Update(npcs, CollisionTargets); + Camera.Update(Player.Position, Width); } // Draws everything that's behind the player, from back to front.