Compare commits

..

2 Commits

3 changed files with 21 additions and 12 deletions

View File

@ -18,13 +18,18 @@ namespace SemiColinGames {
public Matrix Projection { 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) { public void Update(float modelTime, Player player, int worldWidth) {
float diff = player.X - bbox.Center.X; Vector2 pos = player.Position;
if (Math.Abs(diff) > 16) { float xDiff = pos.X - bbox.Center.X;
bbox.Offset((int) (diff * 0.1), 0); 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) { if (bbox.Left < 0) {
bbox.Offset(-bbox.Left, 0); bbox.Offset(-bbox.Left, 0);
@ -35,13 +40,14 @@ namespace SemiColinGames {
if (shakeTime > 0) { if (shakeTime > 0) {
shakeTime -= modelTime; shakeTime -= modelTime;
int x = random.Next(-4, 5); int x = random.Next(-4, 5);
bbox.Offset(x, 0); int y = random.Next(-4, 5);
bbox.Offset(x, y);
} }
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() { public void Shake() {
shakeTime = 0.5f; shakeTime = 0.3f;
} }
} }
} }

View File

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

View File

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