|
|
@ -82,7 +82,8 @@ namespace SemiColinGames { |
|
|
|
class World { |
|
|
|
|
|
|
|
public const int TileSize = 16; |
|
|
|
readonly List<Tile> tiles = new List<Tile>(); |
|
|
|
readonly Tile[] tiles; |
|
|
|
readonly Rectangle[] collisionTargets; |
|
|
|
|
|
|
|
public int Width { get; private set; } |
|
|
|
public int Height { get; private set; } |
|
|
@ -106,6 +107,7 @@ namespace SemiColinGames { |
|
|
|
....................] [............................................] [.............] [..............................................................] [.......................................................";
|
|
|
|
|
|
|
|
public World(Texture2D texture) { |
|
|
|
var tilesList = new List<Tile>(); |
|
|
|
string[] worldDesc = worldString.Split('\n'); |
|
|
|
Width = worldDesc.AsQueryable().Max(a => a.Length); |
|
|
|
Height = worldDesc.Length; |
|
|
@ -146,10 +148,15 @@ namespace SemiColinGames { |
|
|
|
} |
|
|
|
if (terrain != Terrain.Empty) { |
|
|
|
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize); |
|
|
|
tiles.Add(new Tile(texture, terrain, position)); |
|
|
|
tilesList.Add(new Tile(texture, terrain, position)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
tiles = tilesList.ToArray(); |
|
|
|
collisionTargets = new Rectangle[tiles.Length]; |
|
|
|
for (int i = 0; i < tiles.Length; i++) { |
|
|
|
collisionTargets[i] = tiles[i].Position; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void Draw(SpriteBatch spriteBatch, Camera camera) { |
|
|
@ -158,12 +165,8 @@ namespace SemiColinGames { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public List<Rectangle> CollisionTargets() { |
|
|
|
var result = new List<Rectangle>(); |
|
|
|
foreach (Tile t in tiles) { |
|
|
|
result.Add(t.Position); |
|
|
|
} |
|
|
|
return result; |
|
|
|
public Rectangle[] CollisionTargets { |
|
|
|
get { return collisionTargets; } |
|
|
|
} |
|
|
|
} |
|
|
|
} |