Esempio n. 1
0
    private void PerlinGeneration(Vector2Int mapSize, int scale, int octaves, float persistence, int lacunarity)
    {
        rdm = new System.Random();
        float random = (float)rdm.NextDouble();

        floatMap = new float[mapSize.x, mapSize.y];
        intMap   = new int[mapSize.x, mapSize.y];
        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                //Debug.Log((float)x / mapSize.x + "," + (float)y / mapSize.y);
                floatMap[x, y] = PerlinNoise.Fbm((float)x / mapSize.x, (float)y / mapSize.y, octaves, lacunarity, persistence * random) + (Mathf.PerlinNoise((float)x / mapSize.x, (float)y / mapSize.y) - 0.5f) * random;
                //Debug.Log((float)x/map.x+","+(float)y/map.y);

                // mapToString += floatMap[x, y] + " ";


                if (floatMap[x, y] < -0.05f)
                {
                    intMap[x, y] = 0;
                }
                else if (floatMap[x, y] >= -0.05f && floatMap[x, y] < 0f)
                {
                    intMap[x, y] = 2;
                }
                else
                {
                    intMap[x, y] = 1;
                }
            }
            //mapToString += "\n";
        }
        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                if (intMap[x, y] == 0)
                {
                    topMap.SetTile(new Vector3Int(-x + width / 2, -y + height / 2, 0), topTile);
                }
                else
                {
                    botMap.SetTile(new Vector3Int(-x + width / 2, -y + height / 2, 0), botTile);
                }
            }
        }
        //Debug.Log(mapToString);
        mapToString = "";
    }
Esempio n. 2
0
        public World()
        {
            _chunks.Add(new Vector3i(), new Chunk(this));
            for (int z = 0; z < CHUNK_SIZE; z++)
            {
                for (int x = 0; x < CHUNK_SIZE; x++)
                {
                    float height = PerlinNoise.Fbm(x / 40.12412f, z / 40.12412f, 8) * 10 + 10;
                    bool  lamp   = Math.Abs(PerlinNoise.Noise(x, z)) > 0.5f;
                    for (int y = 0; y < CHUNK_SIZE; y++)
                    {
                        int i = Vector3IntToIndex(x, y, z);
                        _chunks[new Vector3i()][i] = ((y > height) ? 0 : (y > height - 1) ? 1 : (y > height - 3) ? 3 : 2);
                    }
                }
            }

            _chunks[new Vector3i()][16, 12, 16] = 5;
            _chunks[new Vector3i()][16, 10, 12] = 6;
            _chunks[new Vector3i()][10, 13, 10] = 4;
            _chunks[new Vector3i()][20, 13, 20] = 7;
        }