|
@ -34,12 +34,13 @@ namespace SemiColinGames { |
|
|
private const int swordSwingMax = 6; |
|
|
private const int swordSwingMax = 6; |
|
|
private float ySpeed = 0; |
|
|
private float ySpeed = 0; |
|
|
private double jumpTime = 0; |
|
|
private double jumpTime = 0; |
|
|
|
|
|
private float invincibilityTime = 0; |
|
|
|
|
|
|
|
|
public Player() { |
|
|
public Player() { |
|
|
Health = MaxHealth; |
|
|
Health = MaxHealth; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int MaxHealth { get; private set; } = 5; |
|
|
|
|
|
|
|
|
public int MaxHealth { get; private set; } = 3; |
|
|
|
|
|
|
|
|
public int Health { get; private set; } |
|
|
public int Health { get; private set; } |
|
|
|
|
|
|
|
@ -56,6 +57,8 @@ namespace SemiColinGames { |
|
|
return BoxOffset(position, 0); |
|
|
return BoxOffset(position, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
invincibilityTime -= modelTime; |
|
|
|
|
|
|
|
|
Vector2 movement = HandleInput(modelTime, input); |
|
|
Vector2 movement = HandleInput(modelTime, input); |
|
|
|
|
|
|
|
|
// Broad test: remove all collision targets nowhere near the player.
|
|
|
// Broad test: remove all collision targets nowhere near the player.
|
|
@ -71,11 +74,12 @@ namespace SemiColinGames { |
|
|
new Vector2(halfSize.X + Math.Abs(movement.X) + 1, halfSize.Y + Math.Abs(movement.Y) + 1)); |
|
|
new Vector2(halfSize.X + Math.Abs(movement.X) + 1, halfSize.Y + Math.Abs(movement.Y) + 1)); |
|
|
foreach (var box in collisionTargets) { |
|
|
foreach (var box in collisionTargets) { |
|
|
if (box.Intersect(largeBox) != null) { |
|
|
if (box.Intersect(largeBox) != null) { |
|
|
Debug.AddRect(box, Color.Green); |
|
|
|
|
|
|
|
|
// Debug.AddRect(box, Color.Green);
|
|
|
candidates.Add(box); |
|
|
candidates.Add(box); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool harmedByCollision = false; |
|
|
Point[] movePoints = Line.Rasterize(0, 0, (int) movement.X, (int) movement.Y); |
|
|
Point[] movePoints = Line.Rasterize(0, 0, (int) movement.X, (int) movement.Y); |
|
|
for (int i = 1; i < movePoints.Length; i++) { |
|
|
for (int i = 1; i < movePoints.Length; i++) { |
|
|
int dx = movePoints[i].X - movePoints[i - 1].X; |
|
|
int dx = movePoints[i].X - movePoints[i - 1].X; |
|
@ -86,8 +90,12 @@ namespace SemiColinGames { |
|
|
bool reject = false; |
|
|
bool reject = false; |
|
|
foreach (var box in candidates) { |
|
|
foreach (var box in candidates) { |
|
|
if (box.Intersect(player) != null) { |
|
|
if (box.Intersect(player) != null) { |
|
|
|
|
|
Debug.AddRect(box, Color.Cyan); |
|
|
reject = true; |
|
|
reject = true; |
|
|
break; |
|
|
|
|
|
|
|
|
if (box.Terrain.IsHarmful) { |
|
|
|
|
|
Debug.AddRect(box, Color.Red); |
|
|
|
|
|
harmedByCollision = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (!reject) { |
|
|
if (!reject) { |
|
@ -100,8 +108,12 @@ namespace SemiColinGames { |
|
|
bool reject = false; |
|
|
bool reject = false; |
|
|
foreach (var box in candidates) { |
|
|
foreach (var box in candidates) { |
|
|
if (box.Intersect(player) != null) { |
|
|
if (box.Intersect(player) != null) { |
|
|
|
|
|
Debug.AddRect(box, Color.Cyan); |
|
|
reject = true; |
|
|
reject = true; |
|
|
break; |
|
|
|
|
|
|
|
|
if (box.Terrain.IsHarmful) { |
|
|
|
|
|
Debug.AddRect(box, Color.Red); |
|
|
|
|
|
harmedByCollision = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (!reject) { |
|
|
if (!reject) { |
|
@ -114,8 +126,12 @@ namespace SemiColinGames { |
|
|
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); |
|
|
standingOnGround = true; |
|
|
standingOnGround = true; |
|
|
break; |
|
|
|
|
|
|
|
|
if (box.Terrain.IsHarmful) { |
|
|
|
|
|
Debug.AddRect(box, Color.Red); |
|
|
|
|
|
harmedByCollision = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -133,6 +149,11 @@ namespace SemiColinGames { |
|
|
Debug.AddRect(Box(position), Color.Orange); |
|
|
Debug.AddRect(Box(position), Color.Orange); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (harmedByCollision && invincibilityTime <= 0) { |
|
|
|
|
|
Health -= 1; |
|
|
|
|
|
invincibilityTime = 0.6f; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (movement.X > 0) { |
|
|
if (movement.X > 0) { |
|
|
Facing = 1; |
|
|
Facing = 1; |
|
|
} else if (movement.X < 0) { |
|
|
} else if (movement.X < 0) { |
|
@ -242,7 +263,11 @@ namespace SemiColinGames { |
|
|
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset); |
|
|
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset); |
|
|
SpriteEffects effect = Facing == 1 ? |
|
|
SpriteEffects effect = Facing == 1 ? |
|
|
SpriteEffects.FlipHorizontally : SpriteEffects.None; |
|
|
SpriteEffects.FlipHorizontally : SpriteEffects.None; |
|
|
spriteBatch.Draw(Textures.Player.Get, position.ToVector2(), textureSource, Color.White, 0f, |
|
|
|
|
|
|
|
|
Color color = Color.White; |
|
|
|
|
|
if (invincibilityTime > 0 && invincibilityTime % 0.2f > 0.1f) { |
|
|
|
|
|
color = new Color(0.5f, 0.5f, 0.5f, 0.5f); |
|
|
|
|
|
} |
|
|
|
|
|
spriteBatch.Draw(Textures.Player.Get, position.ToVector2(), textureSource, color, 0f, |
|
|
spriteCenter, Vector2.One, effect, 0f); |
|
|
spriteCenter, Vector2.One, effect, 0f); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|