Ejemplo n.º 1
0
    private void CreateBiome(DraftHexPrefab hex)
    {
        //alpha from height
        float alpha = hex.InfoScript.Height / 1000f;

        alpha = LerpAlpha(alpha);

        //color from biome
        Dictionary <string, Color> biomeColors = new Dictionary <string, Color>()
        {
            { "snow", new Color(1, 1, 1, 1) },
            { "show mountain", new Color(0.8f, 0.8f, 0.8f, 1) },
            { "mountain", new Color(0.5f, 0.5f, 0.5f, 1) },
            { "grass", new Color(0.29f, 0.76f, 0.25f, 1) },
            { "desert", new Color(1, 1, 0, 1) }
        };

        string biome = GetBiomName(hex);

        hex.InfoScript.Biome = biome;

        var color = biomeColors[biome];

        color.a           = alpha;
        hex.BGImage.color = color;
    }
Ejemplo n.º 2
0
    private void BlendEdges()
    {
        if (BlendingValue == 0)
        {
            return;
        }

        int edge = BlendingValue / 2;
        int j    = 0;

        DraftHexPrefab[,] edgeHexes = new DraftHexPrefab[HexCountY, BlendingValue];
        float[,] edgeHeights        = new float[HexCountY, BlendingValue];

        float[] avg = new float[HexCountY];
        float[,] rndMap = PerlinNoise.GenerateNoiseMap(HexCountY, BlendingValue, Seed, NoiseScale / 833, Octaves, Persistance, Lacunarity, Offset);
        for (int i = 0; i < HexCountY; i++)
        {
            for (int g = 0; g < BlendingValue; g++)
            {
                rndMap[i, g] = Mathf.Lerp(5, 10, rndMap[i, g]); // => Random.Range(5, 10)
            }
        }
        for (int i = 0; i < HexCountY; i++)
        {
            for (int k = 0; k < BlendingValue; k++)
            {
                if (k < edge)
                {
                    j = k;
                }
                else
                {
                    j = HexCountX + edge - k - 1;
                }

                edgeHexes[i, k]   = _hexes[j, i];
                edgeHeights[i, k] = _heights[j, i];
                avg[i]           += _heights[j, i];
            }
        }

        for (int x = 0; x < HexCountY; x++)
        {
            for (int y = 0; y < BlendingValue; y++)
            {
                avg[y] = avg[y] / BlendingValue;
                float height = edgeHeights[x, y];
                height -= (height - avg[y]) / rndMap[x, y];
                edgeHexes[x, y].Height.text = (height * 1000).ToString("0");

                var color = edgeHexes[x, y].BGImage.color;
                color.a = LerpAlpha(height);
                edgeHexes[x, y].BGImage.color = color;
                //edgeHexes[x, y].BGImage.color = new Color(0, 0, 0, 1); ///debug
            }
        }
    }
Ejemplo n.º 3
0
    private string GetBiomName(DraftHexPrefab hexObject)
    {
        var    hex   = hexObject.InfoScript;
        string biome = null;

        float maxDesertHumidity = 0.4f / 0.22f * DesertPercent;

        if (hex.Temperature <= 0.25f)
        {
            if (hex.Height <= _mountainsLevel)
            {
                biome = "snow";
            }
            else
            {
                biome = "show mountain";
                _mountains.Add(hexObject);
            }
        }

        else if (hex.Height > _mountainsLevel)
        {
            biome = "mountain";
            _mountains.Add(hexObject);
        }

        //else if (hex.Humidity <= 0.4f && hex.Temperature > 0.55f)
        else if (hex.Humidity <= maxDesertHumidity && hex.Temperature > 0.55f && DesertPercent >= 0.01f)
        {
            biome = "desert";
        }

        else
        {
            biome = "grass";
        }


        return(biome);
    }
Ejemplo n.º 4
0
    private void GenerateRivers()
    {
        foreach (var spring in _springs)
        {
            spring.DraftRiver.SetActive(true);
            float          minDistance  = float.MaxValue;
            DraftHexPrefab nearestWater = null;

            foreach (var hex in _waterHexes)
            {
                float distance = Vector3.Distance(spring.transform.position, hex.transform.position);

                if (distance < minDistance)
                {
                    minDistance  = distance;
                    nearestWater = hex;
                }
            }

            nearestWater.DraftRiverEnd.SetActive(true);
        }
    }