예제 #1
0
        public PointF[] GenerateArm(int numOfStars, float rotation, float spin, double armSpread, int armNo)
        {
            PointF[] result = new PointF[numOfStars];
            Random   r      = new Random();

            //stars = armNo % 2 = 0
            //nebual = armNo % 2 != 0

            double armSpread2 = armSpread;

            if (armNo % 2 != 0)
            {
                numOfStars = numOfStars / 2;
            }
            for (int i = 0; i < numOfStars; i++)
            {
                if (armNo % 2 != 0)
                {
                    //ToDo: both values should be parameters, in the form and contract
                    // skip the first nebulas, so that the center remains clean
                    if (i < 7)
                    {
                        continue;
                    }



                    //reduce armspread if the nebula is near the center
                    armSpread2 = armSpread;
                    if (i < 200)
                    {
                        armSpread2 = armSpread2 * ((i + 1) / 200.0);
                    }
                }

                var centerRatio = armNo % 2 == 0 ? starsAtCenterRatio : nebulaAtCenterRatio;

                double part = (double)i / (double)numOfStars;
                part = Math.Pow(part, centerRatio);

                float  distanceFromCenter = (float)part;
                double position           = (part * spin + rotation) * Math.PI * 2;

                double xFluctuation = (Pow3Constrained(r.NextDouble()) - Pow3Constrained(r.NextDouble())) * armSpread2;
                double yFluctuation = (Pow3Constrained(r.NextDouble()) - Pow3Constrained(r.NextDouble())) * armSpread2;

                float resultX = (float)Math.Cos(position) * distanceFromCenter / 2 + 0.5f + (float)xFluctuation;
                float resultY = (float)Math.Sin(position) * distanceFromCenter / 2 + 0.5f + (float)yFluctuation;

                result[i] = new PointF(resultX, resultY);
                Star star = transform(result[i], armNo % 2 == 0 ? 1 : 2);

                //this.stars.Add(star);
                Map.addStar(star);
            }

            return(result);
        }
예제 #2
0
        public void SpreadNebula()
        {
            GalaxyMap temporaryNebulas = new GalaxyMap(Map.Settings);

            foreach (var star in Map.stars)
            {
                if (star.StarNebulaType == 1)
                {
                    continue;
                }

                //spread temporary nebula (StarNebulaType = 3)  in a circle with a radius of 4 fields:
                for (int x = star.X - 4; x < star.X + 4; x++)
                {
                    for (int y = star.Y - 4; y < star.Y + 4; y++)
                    {
                        if (x == star.X && y == star.Y)
                        {
                            continue;
                        }

                        var distance    = Math.Sqrt(((star.X - x) * (star.X - x)) + ((star.Y - y) * (star.Y - y)));
                        var probability = (1 / distance) * 30;

                        //try to find;
                        //Star checker = new Star(x, y, 3, this);
                        Star checker = StarGenerator.MakeStarXY(false, x, y);
                        checker.StarNebulaType = 3;

                        temporaryNebulas.addStar(checker, false, false);
                        checker.NebulaPercentage += (int)probability;
                    }
                }
            }

            Random r = new Random();

            //temporaryNebulas.stars.ForEach(e => Map.addStar(e,false,false));
            //stars.AddRange(toAdd);
            foreach (var star in temporaryNebulas.stars)
            {
                if (star.NebulaPercentage < 8)
                {
                    continue;
                }

                int percentage = Math.Min(star.NebulaPercentage, 90);
                int rand       = r.Next(100);
                if (rand < percentage)
                {
                    star.StarNebulaType = 2;
                    Map.addStar(star, false, true);
                }
            }


            //this.Refresh();
        }
예제 #3
0
        public void GenerateMap(bool shake = true, bool round = true)
        {
            int id = 0;

            for (int i = 0; i < starsInRow; i++)
            {
                for (int j = 0; j < starsInRow; j++)
                {
                    int  x        = (i * distanceBetweenSuns) + 2;
                    int  y        = (j * distanceBetweenSuns) + 2;
                    var  isPlayer = id % StarsPerPlayer == 0 ? true : false;
                    Star tempStar = StarGenerator.MakeStarXY(isPlayer, x, y);

                    tempStar.Id = id;
                    if (shake)
                    {
                        ShakePosition(tempStar);
                    }

                    stars.Add(tempStar);
                    starsToShake.Add(tempStar);
                    id++;
                }
            }
            if (Textbox != null)
            {
                Textbox.Text = id.ToString() + " - " + stars.Count.ToString() + "  generierte Star Location: " + Environment.NewLine;
            }

            //needed because stars may be too near to each other when shaking was used during star placement
            if (shake)
            {
                shakeAndCheck(0);
            }

            //make a round galaxy.
            if (round)
            {
                MakeRound();
            }

            stars.ForEach(e => Map.addStar(e));
        }