Initial attempt at road generation

This commit is contained in:
2015-05-26 19:36:44 +03:00
parent b6b2dce32e
commit 22f1905b1b
10 changed files with 239 additions and 10 deletions

View File

@ -13,7 +13,8 @@ namespace TransportGame.MapViewer
None = 0,
Elevation = 1,
Population = 2,
All = Elevation | Population
RoadArticulations = 3,
All = Elevation | Population | RoadArticulations
};
/// <summary>
@ -57,9 +58,13 @@ namespace TransportGame.MapViewer
// Create texture on which to draw
Bitmap24 bitmap = new Bitmap24(Convert.ToInt32(map.Width * Scale), Convert.ToInt32(map.Height * Scale));
// First layer - cells
// Elevation, population
DrawPixels(bitmap, map, (layers & Layers.Elevation) > 0, (layers & Layers.Population) > 0);
// Roads
if ((layers & Layers.RoadArticulations) > 0)
DrawRoads(bitmap, map);
// Done
return bitmap;
}
@ -83,6 +88,12 @@ namespace TransportGame.MapViewer
int mapX = Convert.ToInt32(x / Scale);
int mapY = Convert.ToInt32(y / Scale);
if (mapX >= map.Width)
mapX = map.Width - 1;
if (mapY >= map.Height)
mapY = map.Height - 1;
// Draw water
if (map.IsWater(mapX, mapY))
bitmap[x, y] = WaterColor;
@ -108,5 +119,18 @@ namespace TransportGame.MapViewer
}
}
}
private void DrawRoads(Bitmap24 bitmap, Map map)
{
// Draw road segments
foreach (var pair in map.RoadNetwork.ArticulationSegments)
{
bitmap.DrawLine(Convert.ToInt32(pair.Value.Terminal1.X * Scale),
Convert.ToInt32(pair.Value.Terminal1.Y * Scale),
Convert.ToInt32(pair.Value.Terminal2.X * Scale),
Convert.ToInt32(pair.Value.Terminal2.Y * Scale),
Colors.Black);
}
}
}
}