Browse Source

rename "tiles" to "obstacles"

master
Colin McMillen 4 years ago
parent
commit
36e70989af
  1. 22
      Shared/World.cs

22
Shared/World.cs

@ -35,7 +35,7 @@ namespace SemiColinGames {
// TODO: remove this. // TODO: remove this.
public const int TileSize = 16; public const int TileSize = 16;
readonly Tile[] tiles;
readonly Tile[] obstacles;
readonly Tile[] decorations; readonly Tile[] decorations;
// Kept around for resetting the world's entities after player death or level restart. // Kept around for resetting the world's entities after player death or level restart.
readonly JToken entitiesLayer; readonly JToken entitiesLayer;
@ -134,8 +134,8 @@ namespace SemiColinGames {
} }
// Get all the obstacles into a single array, sorted by X. // Get all the obstacles into a single array, sorted by X.
obstacleTiles.AddRange(hazardTiles); 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 // The background tiles are added before the rest of the decorations, so that they're drawn
// in the back. // in the back.
backgroundTiles.AddRange(decorationTiles); 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 // 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. // 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. // Add a synthetic collisionTarget on the left side of the world.
CollisionTargets[0] = new AABB(new Vector2(-1, 0), new Vector2(1, float.MaxValue)); 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); 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( 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. // 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)); new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
} }
@ -176,6 +176,7 @@ namespace SemiColinGames {
(Player, npcs) = ParseEntities(entitiesLayer); (Player, npcs) = ParseEntities(entitiesLayer);
} }
// Draws everything that's behind the player, from back to front.
public void DrawBackground(SpriteBatch spriteBatch) { public void DrawBackground(SpriteBatch spriteBatch) {
foreach (Tile t in decorations) { foreach (Tile t in decorations) {
t.Draw(spriteBatch); 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) { public void DrawForeground(SpriteBatch spriteBatch) {
foreach (Tile t in tiles) {
foreach (Tile t in obstacles) {
t.Draw(spriteBatch); t.Draw(spriteBatch);
} }
} }

Loading…
Cancel
Save