Exemple #1
0
        public BiomeMap(TerrainGenerator newTerrainData)
        {
            m_terrainData = newTerrainData;
            m_data = new BiomeMapPixel[Size, Size];

            //Set biome weights for all pixels
            Point position;
            for (int x = 0; x < Size; ++x)
            {
                for (int y = 0; y < Size; ++y)
                {
                    position = new Point(x, y);

                    float heightAboveSeaLevel = m_terrainData.GetHeightAboveSeaLevelAt(position);
                    float latitude = Mathf.Clamp(position.y / (float)m_terrainData.Heightmap.size, 0f, 1f);
                    float precipitation = m_terrainData.Rainmap.GetValueAt(position);

                    m_data[y, x] = new BiomeMapPixel(latitude, heightAboveSeaLevel, precipitation);
                }
            }

            //Iterate through all pixels, setting their parent Biome
            for (int x = 0; x < Size; ++x)
            {
                for (int y = 0; y < Size; ++y)
                {
                    //Ignore pixels that have already had their parent biome set.
                    if (m_data[y, x].ParentBiome != null)
                    {
                        continue;
                    }

                    //Generate a new Biome object from the primary biome type of this pixel.
                    Biome biome = new Biome(m_data[y, x].GetPrimaryBiome());

                    //Flood fill the map with that biome.
                    floodFill(new Point(x, y), biome);

                    //Generate a name for that biome, now that it knows how big it is.
                    biome.GenerateName();
                }
            }
        }