Пример #1
0
    void GeneratePositions()
    {
        for (int x = 0; x < chunkSize; x++)
        {
            for (int z = 0; z < chunkSize; z++)
            {
                if (transform.localPosition.y >= 0)
                {
                    int height = (int)(Noise.EvaluateNoise2D(new Vector2((x + transform.localPosition.x + World.instance.seed) * World.instance.noiseFrequency, (z + transform.localPosition.z + World.instance.seed) * World.instance.noiseFrequency)) * World.instance.noiseAmplitude);

                    for (int h = height; h >= 0; h--)
                    {
                        float n3d = Noise.EvaluateNoise3D((new Vector3(((x + transform.localPosition.x + World.instance.seed) * 0.04f), ((h + transform.localPosition.y + World.instance.seed) * 0.04f), ((z + transform.localPosition.z + World.instance.seed) * 0.04f))));

                        if (n3d > -0.5f)
                        {
                            if (h == height)
                            {
                                if (h > 7)
                                {
                                    AddPos(new Vector3Int(x, h, z), BlockDatabase.BlockType.GRASS);
                                }

                                else
                                {
                                    AddPos(new Vector3Int(x, h, z), BlockDatabase.BlockType.SAND);
                                }

                                int spawnTree = Random.Range(0, 200);



                                if (h > 8 && spawnTree > 196 && World.instance.GenerateTrees)
                                {
                                    GenerateTree(new Vector3Int(x, h, z));
                                }
                            }
                            else if (h > height - 6)
                            {
                                AddPos(new Vector3Int(x, h, z), BlockDatabase.BlockType.DIRT);
                            }
                            else
                            {
                                float oreNoise = Noise.EvaluateNoise3D((new Vector3(((x + transform.localPosition.x + World.instance.seed) * 0.9f), ((h + transform.localPosition.y + World.instance.seed) * 0.9f), ((z + transform.localPosition.z + World.instance.seed) * 0.9f))));


                                if (oreNoise < 0.7f)
                                {
                                    AddPos(new Vector3Int(x, h, z), BlockDatabase.BlockType.STONE);
                                }
                                else if (oreNoise < 0.85f)
                                {
                                    AddPos(new Vector3Int(x, h, z), BlockDatabase.BlockType.COAL);
                                }
                                else
                                {
                                    AddPos(new Vector3Int(x, h, z), BlockDatabase.BlockType.IRON);
                                }
                            }
                        }

                        if (h <= 5)
                        {
                            for (int w = h + 1; w <= 5; w++)
                            {
                                AddPos(new Vector3Int(x, w, z), BlockDatabase.BlockType.WATER);
                            }
                        }
                    }
                }
                else if (transform.localPosition.y < 0)
                {
                    for (int y = 0; y < chunkSize; y++)
                    {
                        float n3d = Noise.EvaluateNoise3D((new Vector3(((x + transform.localPosition.x + World.instance.seed) * 0.04f), ((y + transform.localPosition.y + World.instance.seed) * 0.04f), ((z + transform.localPosition.z + World.instance.seed) * 0.04f))));

                        if (n3d > -0.4f)
                        {
                            float oreNoise = Noise.EvaluateNoise3D((new Vector3(((x + transform.localPosition.x + World.instance.seed) * 0.9f), ((y + transform.localPosition.y + World.instance.seed) * 0.9f), ((z + transform.localPosition.z + World.instance.seed) * 0.9f))));

                            if (oreNoise < 0.6f)
                            {
                                AddPos(new Vector3Int(x, y, z), BlockDatabase.BlockType.STONE);
                            }
                            else if (oreNoise < 0.8f)
                            {
                                AddPos(new Vector3Int(x, y, z), BlockDatabase.BlockType.COAL);
                            }
                            else
                            {
                                AddPos(new Vector3Int(x, y, z), BlockDatabase.BlockType.IRON);
                            }
                        }
                    }
                }
            }
        }
    }