Пример #1
0
    /* METHODS */
    public GameObject[,] GenerateTileArray(Coordinates.ChunkCoordinates chunkCoordinates, int seed)
    {
        GameObject[,] chunkMap = new GameObject[chunkTileWidth, chunkTileWidth];
        // Initializer the generators with the given seed so that each chunk has a unique generator
        InitGenerators(chunkCoordinates, seed);

        for (int i = 0; i < chunkTileWidth; i++)
        {
            for (int j = 0; j < chunkTileWidth; j++)
            {
                //Fill the chunk with grass terrain to start
                chunkMap[i, j] = mapGenerationData.grassTilePrefab;
            }
        }

        // generate elevation maps for given chunk and adjacent chunks
        GenerateElevationMap();

        // Pass reference to the chunkMap through each of our terrain generators and return
        GenerateMountains(chunkMap);
        GenerateRiverValleys(chunkMap);
        GenerateWaterBodies(chunkMap);

        return(chunkMap);
    }
Пример #2
0
 /// <summary>
 /// Initializes a random number generator for each local chunk. Each chunk had it's own seed based on the world seed and it's own chunk location.
 /// </summary>
 /// <param name="chunkLocation"></param>
 void InitGenerators(Coordinates.ChunkCoordinates chunkLocation, int seed)
 {
     for (int i = 0; i < generatorMatrix.GetLength(0); i++)
     {
         for (int j = 0; j < generatorMatrix.GetLength(1); j++)
         {
             int chunkSeed = (int)(seed + chunkLocation.X - 1 + i + Mathf.RoundToInt(Mathf.Pow(chunkLocation.Y - 1 + j, 2)));
             generatorMatrix[i, j] = new System.Random(chunkSeed);
         }
     }
 }