public void Generate(ProgressBar progress, int type) { progress.Value = 40; MapHeights heights = MapHeights.creates[type](Width, Height); progress.Value = 70; int[,] distribution = Utilites.DFS <double>(heights.Map, (double a) => { return(a < Water.seaLevel); }); progress.Value = 80; MapNormals normals = new MapNormals(heights); progress.Value = 90; initLight(); progress.Value = 92; initCells(new Size(Form1.CELL_SIZE, Form1.CELL_SIZE), heights, normals, Light, distribution); Light.FirstPass(); progress.Value = 95; }
private void initCells(Size cellSize, MapHeights heights, MapNormals normals, Lighting light, int[,] distribution) { for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { if (Map[i, j] == null) { Map[i, j] = new Cell(i, j, cellSize); } for (int k = 0; k < cellSize.Width; k++) { for (int s = 0; s < cellSize.Height; s++) { int x = Map[i, j].Location.X + k; int y = Map[i, j].Location.Y + s; int cx = i * cellSize.Width + k; int cy = j * cellSize.Height + s; switch (distribution[cx, cy] == 0 ? Cell.Element.GROUND : Cell.Element.WATER) { case Cell.Element.WATER: Map[i, j][k, s] = new Cell.Property( new Water(x, y, heights[cx, cy]), new Normal(x, y, normals[cx, cy])); break; case Cell.Element.GROUND: Map[i, j][k, s] = new Cell.Property( new Ground(x, y, heights[cx, cy], normals[cx, cy]), new Normal(x, y, normals[cx, cy])); break; } if (Map[i, j][k, s].Height is IBrightness) { light.Add((IBrightness)Map[i, j][k, s].Height); } } } } } }