Пример #1
0
        /// <summary>
        /// Make a new biome map for a given level:
        /// </summary>
        /// <param name="seed"></param>
        /// <param name="biomeTypes"></param>
        protected BiomeMap(Level level, int numberOfVoronoiPoints = 250)
        {
            /// init randomness
            seed  = level.seed;
            noise = new FastNoise(seed);

            /// Generate the biome map using a voronoi diagram with a random set of points
            //Generate the random sites
            List <Vector2> randomBiomeCenters = new List <Vector2>();
            int            max     = level.chunkBounds.x * Chunk.Diameter;
            int            bigSize = max * 5;

            Random.InitState(seed);
            for (int i = 0; i < numberOfVoronoiPoints; i++)
            {
                int randomX = Random.Range(0, max);
                int randomZ = Random.Range(0, max);
                randomBiomeCenters.Add(new Vector2(randomX, randomZ));
            }

            // add a star around the random points to clean them up
            randomBiomeCenters.Add(new Vector2(0f, bigSize));
            randomBiomeCenters.Add(new Vector2(0f, -bigSize));
            randomBiomeCenters.Add(new Vector2(bigSize, 0f));
            randomBiomeCenters.Add(new Vector2(-bigSize, 0f));

            // generate the cells based on the centers
            Dictionary <Vertex, Polygon> voronoiCells = Delaunay.GenerateVoronoiCells(
                Delaunay.GenerateTriangulation(randomBiomeCenters)
                );

            // generate the biomes from the voronoi cells.
            foreach (Polygon voronoiCell in voronoiCells.Values)
            {
                assignBiomeToVoronoiCell(voronoiCell);
            }
        }