コード例 #1
0
ファイル: RegionBase.cs プロジェクト: Nitrokitty/SomeGameName
    public virtual float[,] CreateMountains()
    {
        bool         canCreateMountain;
        List <float> heights = new List <float>();

        //Debug.Log(Length);

        for (int j = 0; j < Length; j++)
        {
            for (int i = 0; i < Length; i++)
            {
                if (IsInGrasslands(i, j))
                {
                    Map[j, i] = 0f;
                    continue;
                }
                canCreateMountain = true;

                foreach (var m in Mountains)
                {
                    canCreateMountain &= m.CanCreateNewMountain(i, j);
                }

                if (canCreateMountain && GetRandomChance(Hillyness) && Mountains.Count <= MaxNumberOfMountainsAtOneTime)
                {
                    var   radius = 0f;
                    float h      = GetRandomHillHeight();
                    h = (1 / (11 - h));
                    do
                    {
                        radius = (GetRandomHillWidth() / 10f) * Length / 2f;
                    }while (radius == 0 && Mathf.Asin(h * TerrainHeight / radius) * (180f / Mathf.PI) > 35);

                    //radius = radius * Length * Length;
                    var centerX = radius + i;
                    var centerY = radius + j;
                    Mountains.Add(new Mountain(radius, (int)centerX, (int)centerY, h * RegionBase.TerrainMaxHeight));
                }

                heights.Clear();
                var tempMountain = new Mountain[Mountains.Count];
                Mountains.CopyTo(tempMountain);

                foreach (var m in tempMountain)
                {
                    if (m.IsInMountain(i, j))
                    {
                        heights.Add(m.HeightAtPosition(i, j));
                    }
                    else if (m.CanRemoveMountain(i, j))
                    {
                        Mountains.Remove(m);
                    }
                }

                Map[j, i] = heights.Count == 0 ? 0f : GetMaxHeight(heights);
            }
        }
        return(Map);
    }
コード例 #2
0
        private void UpdateMountain(MountainsModel mountain)
        {
            var index = Mountains.IndexOf(mountain);

            Mountains.Remove(mountain);
            Mountains.Insert(index, mountain);
        }