I'm making a random City generator in C# using XNA, based on a tile engine with tiles of 16x16. I've generated roads in a grid pattern and put them in a List<T>
with the position in pixels and also by tile coordinates. So I have set the tile the road is using as "Occupied = true" and tried to fill in any remaining unused tiles with buildings.
However the difficulty is that I want the building texture to be bigger than the just one tile. My tiles are organised in another List<T>
and have an occupied property so I can check weather it is filled or not. So I need to check the property of 4 tiles in a 32x32 rectangle to see weather they are occupied and if not place a building there.
I have achieved this, however it is terribly slow and inefficient as it loops through every tile and checks the entire list 4 times per loop. So I'm looking for a better way to do this. I'm also aware that my entire system might be kinda stupid, but I'm new and am trying to achieve this using my limited knowledge.
foreach (Tile Tile in Tiles) {
Tile Tile1 = Tiles.Find(delegate(Tile T1) { return T1.TileCoords() ==
new Vector2(X, Y) && T1.Occupied == false; });
Tile Tile2 = Tiles.Find(delegate(Tile T1) { return T1.TileCoords() ==
new Vector2(X + 1, Y) && T1.Occupied == false; });
Tile Tile3 = Tiles.Find(delegate(Tile T1) { return T1.TileCoords() ==
new Vector2(X, Y + 1) && T1.Occupied == false; });
Tile Tile4 = Tiles.Find(delegate(Tile T1) { return T1.TileCoords() ==
new Vector2(X + 1, Y + 1) && T1.Occupied == false; });
if (Tile1 != null && Tile2 != null && Tile3 != null && Tile4 != null) {
MyBuildings.Add(new Buildings(new Rectangle(Tile1.Rectangle.X,
Tile1.Rectangle.Y, Engine.TileWidth * 2, Engine.TileHeight * 2)));
Tile1.Occupied = true;
Tile1.OccupiedWith = "Building";
Tile2.Occupied = true;
Tile2.OccupiedWith = "Building";
Tile3.Occupied = true;
Tile3.OccupiedWith = "Building";
Tile4.Occupied = true;
Tile4.OccupiedWith = "Building";
}
if (X > WorldSize.X / 16) {
X = 0;
Y++;
} else
X++;
}