Browse Source

bound camera y-position by world & change dynamics slightly

master
Colin McMillen 4 years ago
parent
commit
fccca0c676
  1. 13
      Shared/Camera.cs
  2. 2
      Shared/World.cs

13
Shared/Camera.cs

@ -21,22 +21,31 @@ namespace SemiColinGames {
get => Matrix.CreateOrthographicOffCenter(Left, Left + Width, Height + Top, Top, -1, 1); 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; Vector2 pos = player.Position;
float xDiff = pos.X - bbox.Center.X; float xDiff = pos.X - bbox.Center.X;
float yDiff = pos.Y - bbox.Center.Y; float yDiff = pos.Y - bbox.Center.Y;
if (Math.Abs(xDiff) > 16) { if (Math.Abs(xDiff) > 16) {
bbox.Offset((int) (xDiff * 0.1), 0); bbox.Offset((int) (xDiff * 0.1), 0);
} }
if (Math.Abs(yDiff) > 16 && player.StandingOnGround) {
if (player.StandingOnGround) {
bbox.Offset(0, (int) (yDiff * 0.1)); bbox.Offset(0, (int) (yDiff * 0.1));
} }
if (yDiff > 16) {
bbox.Offset(0, (int) (yDiff * 0.2));
}
if (bbox.Left < 0) { if (bbox.Left < 0) {
bbox.Offset(-bbox.Left, 0); bbox.Offset(-bbox.Left, 0);
} }
if (bbox.Right > worldWidth) { if (bbox.Right > worldWidth) {
bbox.Offset(worldWidth - bbox.Right, 0); 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) { if (shakeTime > 0) {
shakeTime -= modelTime; shakeTime -= modelTime;
int x = random.Next(-4, 5); int x = random.Next(-4, 5);

2
Shared/World.cs

@ -162,7 +162,7 @@ namespace SemiColinGames {
Reset(); Reset();
} }
LinesOfSight.Update(npcs, CollisionTargets); LinesOfSight.Update(npcs, CollisionTargets);
Camera.Update(modelTime, Player, Width);
Camera.Update(modelTime, Player, Width, Height);
} }
public void ScreenShake() { public void ScreenShake() {

Loading…
Cancel
Save