public static Map FromImage( Image image ) { Bitmap bitmap = new Bitmap(image); Map map = new Map(); Dictionary<Color, Room> RoomIDMap = new Dictionary<Color, Room>(); Surface wall = new Surface(); wall.Texture = "default_wall"; int wallID = 0; map.Surfaces.Add(wallID,wall); Surface floor = new Surface(); floor.Texture = "default_floor"; int floorID = 1; map.Surfaces.Add(floorID,floor); for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { if (PosIsTile(x, y, bitmap)) { Color c = bitmap.GetPixel(x, bitmap.Height - y- 1); Room room = null; if (RoomIDMap.ContainsKey(c)) room = RoomIDMap[c]; else { room = new Room(); RoomIDMap.Add(c, room); } Tile tile = new Tile(); tile.Location = new Point(x,y); if (IsDoor(tile.Location, bitmap)) tile.Type = Tile.TileType.ClosedDoor; else tile.Type = Tile.TileType.Open; tile.Floor = floorID; foreach (Direction dir in FindWallDirections(tile.Location, bitmap)) tile.Walls.Add(dir, wallID); room.Tiles.Add(tile); } } } bitmap.Dispose(); foreach (KeyValuePair<Color, Room> i in RoomIDMap) map.Rooms.Add(i.Value); return map; }
private void DrawRoom( Graphics graphics, Room room ) { if (!RoomColorMap.ContainsKey(room)) RoomColorMap.Add(room,Color.FromArgb(255, rand.Next(255), rand.Next(255), rand.Next(255))); Color color = RoomColorMap[room]; Brush brush = new SolidBrush(color); foreach (Tile tile in room.Tiles) DrawTile(graphics, brush, tile); brush.Dispose(); }