示例#1
0
        public PlanetaryObject(string name, int i, SolarSystem parent, PlanetaryType type, PlanetarySubType subType) : base()
        {
            Parent = parent;
            Name   = name;
            Color  = Color.White;
            Seed   = Guid.NewGuid().GetHashCode();

            Type    = type;
            SubType = subType;

            if (Type == PlanetaryType.Planet && Parent != null)
            {
                Name        = PlanetNamer.AddSuffix(Parent.NameStyle, Name, i);
                Description = i.AddOrdinal() + " Planet, " + subType.Name;
            }
            else if (Type == PlanetaryType.Sun)
            {
                Description = SubType.Name + " - Planetary System";
            }
        }
示例#2
0
        public void Generate()
        {
            Debug.Assert(Systems.Count <= 0, "Universe already created");

            //Create a galaxy
            Galaxy g = new Galaxy()
            {
                Position = Vector2.Zero
            };

            //Add solar systems
            for (int i = 0; i < total * total; i++)
            {
                int posX = ((i % total) * apart) + Game.random.Next(-deviation, deviation);
                int posY = ((i / total) * apart) + Game.random.Next(-deviation, deviation);
                //Add system
                if (i == 0)
                {
                    g.Children.Add(new SolarSystem()
                    {
                        Name     = PlanetNamer.NamePlanet(),
                        Position = Vector2.Zero,
                    });
                }
                else
                {
                    Vector2 Position = new Vector2(posX, posY);
                    g.Children.Add(new SolarSystem()
                    {
                        Name     = PlanetNamer.NamePlanet(),
                        Position = Position,
                    });
                }


                //Planets per system
                int totalPlanets = Game.random.Deviation(3, 11, 7);
                //Loop through planets to be made
                for (int planet = 0; planet < totalPlanets; planet++)
                {
                    //First object is always a sun
                    if (planet == 0)
                    {
                        //Choose a type of sun
                        PlanetarySubType SubType = SunType.GetRandom();

                        //Add and set it up
                        g.Children[i].Children.Add(new PlanetaryObject(g.Children[i].Name, planet, g.Children[i], PlanetaryType.Sun, SubType)
                        {
                            Diameter    = Game.random.Deviation((SubType as SunType).MinDiameter, (SubType as SunType).MaxDiameter, (SubType as SunType).AvgDiameter),
                            Color       = ((SunType)SubType).Colors[Game.random.Next(0, ((SunType)SubType).Colors.Length)],
                            OuterRadius = 0,
                            Position    = g.Children[i].Position,
                            Angle       = 0,
                        });
                    }
                    //Others are planets
                    else
                    {
                        //Choose type of planet
                        PlanetarySubType SubType = PlanetType.GetRandom((float)planet / (float)totalPlanets);

                        //Choose diameter
                        int Diameter = (int)MathHelper.Clamp(((float)(planet - 1) / (float)totalPlanets <= .5f ? (int)(((float)(planet - 1) / (float)totalPlanets) * (100f * 2)) + 156 : (int)((1f - ((float)(planet) / ((float)totalPlanets - 1))) * (100f * 2)) + 156) + Game.random.Next(-30, 30), 156, 256);

                        //Choose 'outer radius', the ring
                        float OuterRadius = 0;
                        if (planet == 1)     //First planet in system
                        {
                            OuterRadius = (g.Children[i].Children[0].Diameter) + Diameter + Game.random.Next(120, 220);
                        }
                        else
                        {
                            OuterRadius = g.Children[i].Children[planet - 1].OuterRadius + (g.Children[i].Children[planet - 1].Diameter) + Game.random.Next(0, 65);
                        }

                        //Add and set it up
                        g.Children[i].Children.Add(new PlanetaryObject(g.Children[i].Name, planet, g.Children[i], PlanetaryType.Planet, SubType)
                        {
                            Diameter = Diameter,
                            Color    = Color.Lerp(((PlanetType)SubType).Colors[Game.random.Next(0, ((PlanetType)SubType).Colors.Length)],
                                                  ((PlanetType)SubType).Colors[Game.random.Next(0, ((PlanetType)SubType).Colors.Length)], (float)Game.random.NextDouble()),
                            OuterRadius = OuterRadius,
                            Angle       = Game.random.Next(0, 360),
                        });

                        g.Children[i].Radius = OuterRadius;
                    }
                }
            }
            Systems.Add(g);
            HomePlanet = g.Children[(g.Children.Count / 2) + (total / 2)].Children[1];
            TotalSize  = total;
        }