camera now tracks player y-position too

This commit is contained in:
Colin McMillen 2020-03-24 14:41:07 -04:00
parent 3be37740f7
commit e0d5385350
3 changed files with 18 additions and 10 deletions

View File

@ -18,13 +18,18 @@ namespace SemiColinGames {
public Matrix Projection {
get => Matrix.CreateOrthographicOffCenter(Left, Left + Width, Height, 0, -1, 1);
get => Matrix.CreateOrthographicOffCenter(Left, Left + Width, Height + Top, Top, -1, 1);
}
public void Update(float modelTime, Vector2 player, int worldWidth) {
float diff = player.X - bbox.Center.X;
if (Math.Abs(diff) > 16) {
bbox.Offset((int) (diff * 0.1), 0);
public void Update(float modelTime, Player player, int worldWidth) {
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) {
bbox.Offset(0, (int) (yDiff * 0.1));
}
if (bbox.Left < 0) {
bbox.Offset(-bbox.Left, 0);
@ -37,7 +42,7 @@ namespace SemiColinGames {
int x = random.Next(-4, 5);
bbox.Offset(x, 0);
}
Debug.AddToast($"p: {player.X}, {player.Y} c: {bbox.Center.X}");
Debug.AddToast($"p: {pos.X}, {pos.Y} c: {bbox.Center.X}");
}
public void Shake() {

View File

@ -44,8 +44,11 @@ namespace SemiColinGames {
this.position = position;
Facing = facing;
Health = MaxHealth;
StandingOnGround = false;
}
public bool StandingOnGround { get; private set; }
public int MaxHealth { get; private set; } = 3;
public int Health { get; private set; }
@ -129,12 +132,12 @@ namespace SemiColinGames {
}
}
bool standingOnGround = false;
StandingOnGround = false;
AABB groundIntersect = BoxOffset(position, 1);
foreach (var box in candidates) {
if (groundIntersect.Intersect(box) != null) {
Debug.AddRect(box, Color.Cyan);
standingOnGround = true;
StandingOnGround = true;
if (box.Tile?.IsHazard ?? false) {
Debug.AddRect(box, Color.Red);
harmedByCollision = true;
@ -142,7 +145,7 @@ namespace SemiColinGames {
}
}
if (standingOnGround) {
if (StandingOnGround) {
jumps = 1;
ySpeed = -0.0001f;
Debug.AddRect(Box(position), Color.Cyan);

View File

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