Example #1
0
    void DecideCloud(int _x, int _y, int _z, float seed, int size)
    {
        float x = (_x + transform.position.x) * GeneralSettings.cloudScale / (size * GeneralSettings.worldSizeInChunks);
        float y = _y / 4f;
        float z = (_z + transform.position.z) * GeneralSettings.cloudScale / (size * GeneralSettings.worldSizeInChunks);

        if (GeneralSettings.GenerateNoise3D(x + seed + 12.375f, y + seed, z + seed) > 0.56f)
        {
            clouds[_x, _y, _z] = true;
        }
        else
        {
            clouds[_x, _y, _z] = false;
        }
    }
Example #2
0
    private void NoiseMapGeneration(int x, int y, int z)
    {
        float worldPosx = (myPosition.x + x);
        float worldPosy = (myPosition.y + y);
        float worldPosz = (myPosition.z + z);

        int   biomeIndex = 0;
        Biome biome;

        worldPosx *= 1.1f / 100f;
        worldPosz *= 1.1f / 100f;

        float biomeNoise = Mathf.PerlinNoise(worldPosx + seed + 35.8461f, worldPosz + seed + 35.8461f);

        for (int i = 0; i < world.biomesData.biomes.Length; i++)
        {
            biome = world.biomesData.biomes[i];
            if (biomeNoise < biome.maxNoiseForTerrain && biomeNoise >= biome.minNoiseForTerrain)
            {
                biomeIndex = i;
                break;
            }
        }

        worldPosx *= 1.1f * 100f;
        worldPosz *= 1.1f * 100f;

        biome = world.biomesData.biomes[biomeIndex];

        worldPosx *= 1.1f / biome.terrainScale;
        worldPosz *= 1.1f / biome.terrainScale;
        worldPosy /= 128f;

        float noise  = GeneralSettings.GenerateNoise3D(worldPosx + seed, worldPosy + seed, worldPosz + seed);
        float minVal = Mathf.Min(Mathf.Abs(biomeNoise - biome.minNoiseForTerrain), Mathf.Abs(biomeNoise - biome.maxNoiseForTerrain));

        noise += ((float)biome.terrainHeight - y) * 0.5f / (biome.terrainHeight - (float)biome.solidGroundHeight);

        //if (minVal < 0.3f)
        //{
        //    if (biome.biomeName == "Mountains")
        //        noise -= 0.3f - minVal;
        //    else if (biome.biomeName == "Plains")
        //        noise += 0.3f - minVal;
        //if (biome.biomeName == "Mountains")
        //{
        //    noise += 1f;
        //}
        //else if (biome.biomeName == "Plains")
        //{
        //    noise += 1f;
        //}
        //}

        //Basic noisemap generation
        if (noise > 0.25f || y <= biome.solidGroundHeight)
        {
            myBlocks[x, y, z].id = 2;       //Stone
        }
        else
        {
            myBlocks[x, y, z].id = 0;       //Air
        }
        if (y == 0)
        {
            myBlocks[x, y, z].id = 1;       //BedRock
        }
    }
Example #3
0
    private void GenerateTree(int x, int y, int z)
    {
        Biome biome;
        int   biomeIndex = 0;
        float worldPosx  = (myPosition.x + x) * 1.2f / 0.25f;
        float worldPosz  = (myPosition.z + z) * 1.2f / 0.25f;
        float worldPosy  = (myPosition.y + y) / 128f;

        worldPosx *= 1.1f / 100f;
        worldPosz *= 1.1f / 100f;

        float biomeNoise = Mathf.PerlinNoise(worldPosx + seed + 35.8461f, worldPosz + seed + 35.8461f);

        for (int i = 0; i < world.biomesData.biomes.Length; i++)
        {
            biome = world.biomesData.biomes[i];
            if (biomeNoise < biome.maxNoiseForTerrain && biomeNoise >= biome.minNoiseForTerrain)
            {
                biomeIndex = i;
                break;
            }
        }

        worldPosx *= 1.1f * 100f;
        worldPosz *= 1.1f * 100f;

        biome = world.biomesData.biomes[biomeIndex];

        worldPosx  = (myPosition.x + x) * biome.TreePlacementScale;
        worldPosz  = (myPosition.z + z) * biome.TreePlacementScale;
        worldPosy *= 40f;

        int treeHeight = biome.minTreeHeight + (int)(Mathf.PerlinNoise(worldPosx, worldPosz) * (biome.maxTreeHeight - biome.minTreeHeight));

        if (GeneralSettings.GenerateNoise3D(worldPosx + 43.43856f, worldPosy, worldPosz) >= biome.TreePlacementThreshold && myBlocks[x, y, z].id == 2 && y + treeHeight + 2 < GeneralSettings.chunkHeight)
        {
            bool flag = false;
            for (int i = 1; i <= treeHeight; i++)
            {
                if (myBlocks[x, y + i, z].id != 0)
                {
                    flag = true;
                    break;
                }
            }
            for (int i = -3; i <= 3; i++)
            {
                for (int j = -3; j <= 3; j++)
                {
                    if (!world.IsPRCInChunk(new Vector3(x + i, y, z + j)))
                    {
                        flag = true;
                        break;
                    }
                }
            }

            if (!flag)
            {
                for (int i = 1; i <= treeHeight; i++)
                {
                    myBlocks[x, y + i, z].id = 6;       //Oak Log
                }
                for (int i = -3; i <= 3; i++)
                {
                    for (int j = -3; j <= 3; j++)
                    {
                        for (int k = treeHeight - 2; k < treeHeight; k++)
                        {
                            if ((i == 0 && j == 0) || myBlocks[x + i, y + k, z + j].id != 0)
                            {
                                continue;
                            }
                            else
                            {
                                myBlocks[x + i, y + k, z + j].id = 7;       //Leaves
                            }
                        }
                    }
                }
                for (int i = -2; i <= 2; i++)
                {
                    for (int j = -2; j <= 2; j++)
                    {
                        for (int k = treeHeight; k <= treeHeight + 1; k++)
                        {
                            if (i == 0 && j == 0 && k == treeHeight)
                            {
                                continue;
                            }
                            else
                            {
                                myBlocks[x + i, y + k, z + j].id = 7;       //Leaves
                            }
                        }
                    }
                }
                for (int i = -1; i <= 1; i++)
                {
                    for (int j = -1; j <= 1; j++)
                    {
                        myBlocks[x + i, y + treeHeight + 2, z + j].id = 7;       //Leaves
                    }
                }
            }
        }
    }