예제 #1
0
        //1. 先遍历所有的格子, 针对每一个格子产生一个柏林噪声值
        //2. 值最小的地方就是池塘的最低点
        //3. 循环池塘矩形的四条边, 寻找合理的池塘点
        //4. 生命游戏圆滑一个池塘边缘
        //生存着的是池塘
        public int[,] Generate(Vector2Int size)
        {
            if (m_size != size)
            {
                m_perlinMap = new float[size.x, size.y];
                m_pondMap   = new int[size.x, size.y];
                m_size      = size;
            }

            m_lowestSpot  = Vector2Int.zero;
            m_lowestValue = float.MaxValue;

            //对整个地图产生柏林模糊, 然后找到最低点
            for (int y = 0; y < m_size.y; y++)
            {
                for (int x = 0; x < m_size.x; x++)
                {
                    //初始化数据为全部死亡
                    m_pondMap[x, y] = 0;

                    float perlin = CPerlinNoise.NextPerlinNoiseValue(x, y, 0.4f);
                    m_perlinMap[x, y] = perlin;

                    if (perlin > m_lowestValue)
                    {
                        continue;
                    }
                    m_lowestValue = perlin;
                    m_lowestSpot  = new Vector2Int(x, y);
                }
            }

            //两道横边
            for (int x = 0; x < m_size.x; x++)
            {
                Quadrant(x, 0);
                Quadrant(x, m_size.y - 1);
            }

            //两道竖边
            for (int y = 0; y < m_size.y; y++)
            {
                Quadrant(0, y);
                Quadrant(m_size.x - 1, y);
            }

            //平滑池塘
            m_die.SmoothOnce(m_pondMap);
            return(m_pondMap);
        }
예제 #2
0
 public CPerlinMap(int cols, int rows) : base(cols, rows)
 {
     m_perlin = new CPerlinNoise();
 }