Compare commits

...

2 Commits

Author SHA1 Message Date
36e70989af rename "tiles" to "obstacles" 2020-03-08 18:36:42 -04:00
fa4784fc49 IsHarmful -> IsHazard 2020-03-08 18:30:46 -04:00
2 changed files with 17 additions and 15 deletions

View File

@ -94,7 +94,7 @@ namespace SemiColinGames {
if (box.Intersect(player) != null) {
Debug.AddRect(box, Color.Cyan);
reject = true;
if (box.Tile?.IsHarmful ?? false) {
if (box.Tile?.IsHazard ?? false) {
Debug.AddRect(box, Color.Red);
harmedByCollision = true;
}
@ -112,7 +112,7 @@ namespace SemiColinGames {
if (box.Intersect(player) != null) {
Debug.AddRect(box, Color.Cyan);
reject = true;
if (box.Tile?.IsHarmful ?? false) {
if (box.Tile?.IsHazard ?? false) {
Debug.AddRect(box, Color.Red);
harmedByCollision = true;
}
@ -130,7 +130,7 @@ namespace SemiColinGames {
if (groundIntersect.Intersect(box) != null) {
Debug.AddRect(box, Color.Cyan);
standingOnGround = true;
if (box.Tile?.IsHarmful ?? false) {
if (box.Tile?.IsHazard ?? false) {
Debug.AddRect(box, Color.Red);
harmedByCollision = true;
}

View File

@ -15,11 +15,11 @@ namespace SemiColinGames {
Position = position;
this.texture = texture;
this.textureSource = textureSource;
IsHarmful = isHazard;
IsHazard = isHazard;
}
public Rectangle Position { get; private set; }
public bool IsHarmful = false;
public bool IsHazard = false;
public void Draw(SpriteBatch spriteBatch) {
spriteBatch.Draw(
@ -35,7 +35,7 @@ namespace SemiColinGames {
// TODO: remove this.
public const int TileSize = 16;
readonly Tile[] tiles;
readonly Tile[] obstacles;
readonly Tile[] decorations;
// Kept around for resetting the world's entities after player death or level restart.
readonly JToken entitiesLayer;
@ -134,8 +134,8 @@ namespace SemiColinGames {
}
// Get all the obstacles into a single array, sorted by X.
obstacleTiles.AddRange(hazardTiles);
tiles = obstacleTiles.ToArray();
Array.Sort(tiles, CompareByX);
obstacles = obstacleTiles.ToArray();
Array.Sort(obstacles, CompareByX);
// The background tiles are added before the rest of the decorations, so that they're drawn
// in the back.
backgroundTiles.AddRange(decorationTiles);
@ -144,21 +144,21 @@ namespace SemiColinGames {
// The obstacles are sorted by x-position. We maintain this invariant so that it's possible
// to efficiently find CollisionTargets that are nearby a given x-position.
CollisionTargets = new AABB[tiles.Length + 2];
CollisionTargets = new AABB[obstacles.Length + 2];
// Add a synthetic collisionTarget on the left side of the world.
CollisionTargets[0] = new AABB(new Vector2(-1, 0), new Vector2(1, float.MaxValue));
// Now add all the normal collisionTargets for every static terrain tile.
// Now add all the normal collisionTargets for every obstacle.
Vector2 halfSize = new Vector2(TileSize / 2, TileSize / 2);
for (int i = 0; i < tiles.Length; i++) {
for (int i = 0; i < obstacles.Length; i++) {
Vector2 center = new Vector2(
tiles[i].Position.Left + halfSize.X, tiles[i].Position.Top + halfSize.Y);
CollisionTargets[i + 1] = new AABB(center, halfSize, tiles[i]);
obstacles[i].Position.Left + halfSize.X, obstacles[i].Position.Top + halfSize.Y);
CollisionTargets[i + 1] = new AABB(center, halfSize, obstacles[i]);
}
// Add a final synthetic collisionTarget on the right side of the world.
CollisionTargets[tiles.Length + 1] = new AABB(
CollisionTargets[obstacles.Length + 1] = new AABB(
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
}
@ -176,6 +176,7 @@ namespace SemiColinGames {
(Player, npcs) = ParseEntities(entitiesLayer);
}
// Draws everything that's behind the player, from back to front.
public void DrawBackground(SpriteBatch spriteBatch) {
foreach (Tile t in decorations) {
t.Draw(spriteBatch);
@ -185,8 +186,9 @@ namespace SemiColinGames {
}
}
// Draws everything that's in front of the player, from back to front.
public void DrawForeground(SpriteBatch spriteBatch) {
foreach (Tile t in tiles) {
foreach (Tile t in obstacles) {
t.Draw(spriteBatch);
}
}