diff --git a/Shared/World.cs b/Shared/World.cs index a0e4870..4af9082 100644 --- a/Shared/World.cs +++ b/Shared/World.cs @@ -84,7 +84,7 @@ namespace SemiColinGames { public const int TileSize = 16; readonly int width; readonly int height; - readonly Tile[,] tiles; + readonly List tiles = new List(); public int Width { get; } public int Height { get; } @@ -112,7 +112,6 @@ namespace SemiColinGames { width = worldDesc.AsQueryable().Max(a => a.Length); height = worldDesc.Length; Debug.WriteLine("world size: {0}x{1}", width, height); - tiles = new Tile[width, height]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { Terrain terrain = Terrain.Empty; @@ -148,29 +147,24 @@ namespace SemiColinGames { break; } } - var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize); - tiles[i, j] = new Tile(texture, terrain, position); + if (terrain != Terrain.Empty) { + var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize); + tiles.Add(new Tile(texture, terrain, position)); + } } } } public void Draw(SpriteBatch spriteBatch, Camera camera) { - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - tiles[i, j].Draw(spriteBatch, camera); - } + foreach (Tile t in tiles) { + t.Draw(spriteBatch, camera); } } public List CollisionTargets() { var result = new List(); - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - var t = tiles[i, j]; - if (t.Terrain != Terrain.Empty) { - result.Add(t.Position); - } - } + foreach (Tile t in tiles) { + result.Add(t.Position); } return result; }