Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        static PlanetType()
        {
            PlanetTypes = new List <PlanetType>();

            Inferno = new PlanetType("Inferno")
            {
                Range       = new Tuple <float, float>(0, 0.15f),
                Colors      = new Color[] { new Color(190, 100, 15), new Color(190, 40, 15), new Color(220, 80, 0), new Color(220, 160, 0), new Color(220, 120, 60), new Color(230, 40, 0), new Color(250, 180, 0), new Color(230, 30, 0) },
                MinDiameter = 590,
                MaxDiameter = 730,
                AvgDiameter = 660,
            };

            Barren = new PlanetType("Barren")
            {
                Range       = new Tuple <float, float>(Inferno.Range.Item2, 0.17f),
                Colors      = new Color[] { new Color(200, 170, 140), new Color(160, 140, 130), new Color(190, 160, 130) },
                MinDiameter = 590,
                MaxDiameter = 730,
                AvgDiameter = 660,
            };

            Desert = new PlanetType("Desert")
            {
                Range       = new Tuple <float, float>(Barren.Range.Item2, .334f),
                Colors      = new Color[] { new Color(230, 220, 135), new Color(230, 170, 70), new Color(230, 200, 120), },
                MinDiameter = 590,
                MaxDiameter = 730,
                AvgDiameter = 660,
            };

            Tropical = new PlanetType("Tropical")
            {
                Range       = new Tuple <float, float>(.3f, .53f),
                Colors      = new Color[] { new Color(0, 180, 10), new Color(0, 138, 10), new Color(120, 200, 30), new Color(140, 175, 0), new Color(70, 180, 0), new Color(190, 230, 0), new Color(100, 220, 50), new Color(70, 150, 0), new Color(130, 200, 0), },
                MinDiameter = 590,
                MaxDiameter = 730,
                AvgDiameter = 660,
            };

            Temperate = new PlanetType("Temperate")
            {
                Range       = new Tuple <float, float>(.5f, .82f),
                Colors      = new Color[] { new Color(0, 180, 10), new Color(0, 210, 10), new Color(0, 230, 10), new Color(0, 225, 10), new Color(0, 240, 10), new Color(50, 235, 75), new Color(25, 205, 50), new Color(80, 210, 30), new Color(10, 130, 40), new Color(35, 130, 60), new Color(35, 130, 110), new Color(35, 130, 92), new Color(10, 180, 110), new Color(120, 180, 50), new Color(100, 180, 50), },
                MinDiameter = 900,
                MaxDiameter = 1000,
                AvgDiameter = 950,
            };

            Tundra = new PlanetType("Tundra")
            {
                Range       = new Tuple <float, float>(.76f, 0.86f),
                Colors      = new Color[] { new Color(186, 225, 184), new Color(200, 225, 222), new Color(130, 200, 200), new Color(125, 200, 195), new Color(125, 180, 160), new Color(15, 100, 70) },
                MinDiameter = 590,
                MaxDiameter = 730,
                AvgDiameter = 660,
            };
            Artic = new PlanetType("Artic")
            {
                Range       = new Tuple <float, float>(0.86f, 1f),
                Colors      = new Color[] { new Color(200, 225, 240), new Color(140, 150, 240), new Color(30, 125, 140), new Color(125, 200, 195), new Color(100, 220, 230), new Color(90, 160, 230), new Color(230, 250, 252) },
                MinDiameter = 590,
                MaxDiameter = 730,
                AvgDiameter = 660,
            };
        }