Beispiel #1
0
        public void Generate(ProgressBar progress, int type)
        {
            int  w        = Size.Width;
            int  h        = Size.Height;
            Size sizeCell = new Size(Form1.CELL_SIZE, Form1.CELL_SIZE);

            progress.Value = 50;
            MapHeights heights = MapHeights.creates[type](w, h);

            progress.Value      = 97;
            int[,] distribution = Utilites.DFS <double>(heights.Map,
                                                        (double a) =>
            {
                return(a < Water.seaLevel);
            });
            MapNormals normals = new MapNormals(heights);

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    if (cells[i, j] == null)
                    {
                        cells[i, j] = new Cell(i, j, sizeCell);
                    }
                    for (int k = 0; k < sizeCell.Width; k++)
                    {
                        for (int s = 0; s < sizeCell.Height; s++)
                        {
                            int x  = cells[i, j].Location.X + k;
                            int y  = cells[i, j].Location.Y + s;
                            int cx = i * sizeCell.Width + k;
                            int cy = j * sizeCell.Height + s;
                            switch (distribution[cx, cy] == 0 ? Cell.Element.GROUND : Cell.Element.WATER)
                            {
                            case Cell.Element.WATER: cells[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: cells[i, j][k, s] =
                                new Cell.Property(
                                    new Ground(x, y, heights[cx, cy]),
                                    new Normal(x, y, normals[cx, cy]));
                                break;
                            }
                        }
                    }
                }
            }
            progress.Value = 98;
        }
Beispiel #2
0
        private void initCells(Size cellSize, MapHeights heights, MapNormals normals, Light 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.AddItems((IBrightness)Map[i, j][k, s].Height);
                            }
                        }
                    }
                }
            }
        }