コード例 #1
0
ファイル: World.cs プロジェクト: RomaMig/World
        public void Generate(ProgressBar progress, int type)
        {
            Stop();
            //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;
        }
コード例 #2
0
ファイル: World.cs プロジェクト: RomaMig/World
        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;
        }
コード例 #3
0
ファイル: World.cs プロジェクト: RomaMig/World
        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);
                            }
                        }
                    }
                }
            }
        }