World: convert from Tile[][] to List<Tile>
GitOrigin-RevId: 27db59aa1170c63d815d9661ef6e5328a17c6a99
This commit is contained in:
parent
e6fa78e30f
commit
16062f65c3
@ -84,7 +84,7 @@ namespace SemiColinGames {
|
|||||||
public const int TileSize = 16;
|
public const int TileSize = 16;
|
||||||
readonly int width;
|
readonly int width;
|
||||||
readonly int height;
|
readonly int height;
|
||||||
readonly Tile[,] tiles;
|
readonly List<Tile> tiles = new List<Tile>();
|
||||||
|
|
||||||
public int Width { get; }
|
public int Width { get; }
|
||||||
public int Height { get; }
|
public int Height { get; }
|
||||||
@ -112,7 +112,6 @@ namespace SemiColinGames {
|
|||||||
width = worldDesc.AsQueryable().Max(a => a.Length);
|
width = worldDesc.AsQueryable().Max(a => a.Length);
|
||||||
height = worldDesc.Length;
|
height = worldDesc.Length;
|
||||||
Debug.WriteLine("world size: {0}x{1}", width, height);
|
Debug.WriteLine("world size: {0}x{1}", width, height);
|
||||||
tiles = new Tile[width, height];
|
|
||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
Terrain terrain = Terrain.Empty;
|
Terrain terrain = Terrain.Empty;
|
||||||
@ -148,29 +147,24 @@ namespace SemiColinGames {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
|
if (terrain != Terrain.Empty) {
|
||||||
tiles[i, j] = new Tile(texture, terrain, position);
|
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
|
||||||
|
tiles.Add(new Tile(texture, terrain, position));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch, Camera camera) {
|
public void Draw(SpriteBatch spriteBatch, Camera camera) {
|
||||||
for (int j = 0; j < height; j++) {
|
foreach (Tile t in tiles) {
|
||||||
for (int i = 0; i < width; i++) {
|
t.Draw(spriteBatch, camera);
|
||||||
tiles[i, j].Draw(spriteBatch, camera);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Rectangle> CollisionTargets() {
|
public List<Rectangle> CollisionTargets() {
|
||||||
var result = new List<Rectangle>();
|
var result = new List<Rectangle>();
|
||||||
for (int j = 0; j < height; j++) {
|
foreach (Tile t in tiles) {
|
||||||
for (int i = 0; i < width; i++) {
|
result.Add(t.Position);
|
||||||
var t = tiles[i, j];
|
|
||||||
if (t.Terrain != Terrain.Empty) {
|
|
||||||
result.Add(t.Position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user