From fccca0c676ae4e225e74d74893329356eb696800 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 24 Mar 2020 15:05:53 -0400 Subject: [PATCH] bound camera y-position by world & change dynamics slightly --- Shared/Camera.cs | 13 +++++++++++-- Shared/World.cs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Shared/Camera.cs b/Shared/Camera.cs index 8e3e444..7bf683f 100644 --- a/Shared/Camera.cs +++ b/Shared/Camera.cs @@ -21,22 +21,31 @@ namespace SemiColinGames { get => Matrix.CreateOrthographicOffCenter(Left, Left + Width, Height + Top, Top, -1, 1); } - public void Update(float modelTime, Player player, int worldWidth) { + public void Update(float modelTime, Player player, int worldWidth, int worldHeight) { Vector2 pos = player.Position; float xDiff = pos.X - bbox.Center.X; float yDiff = pos.Y - bbox.Center.Y; if (Math.Abs(xDiff) > 16) { bbox.Offset((int) (xDiff * 0.1), 0); } - if (Math.Abs(yDiff) > 16 && player.StandingOnGround) { + if (player.StandingOnGround) { bbox.Offset(0, (int) (yDiff * 0.1)); } + if (yDiff > 16) { + bbox.Offset(0, (int) (yDiff * 0.2)); + } if (bbox.Left < 0) { bbox.Offset(-bbox.Left, 0); } if (bbox.Right > worldWidth) { bbox.Offset(worldWidth - bbox.Right, 0); } + if (bbox.Top < 0) { + bbox.Offset(0, -bbox.Top); + } + if (bbox.Bottom > worldHeight) { + bbox.Offset(0, worldHeight - bbox.Bottom); + } if (shakeTime > 0) { shakeTime -= modelTime; int x = random.Next(-4, 5); diff --git a/Shared/World.cs b/Shared/World.cs index 4c73071..e52fc2e 100644 --- a/Shared/World.cs +++ b/Shared/World.cs @@ -162,7 +162,7 @@ namespace SemiColinGames { Reset(); } LinesOfSight.Update(npcs, CollisionTargets); - Camera.Update(modelTime, Player, Width); + Camera.Update(modelTime, Player, Width, Height); } public void ScreenShake() {