예제 #1
0
        protected internal override IEnumerable <Star> Generate(Random random)
        {
            var density  = _densityMean;
            var countMax = Math.Max(0, (int)(_size * _size * _size * density));

            if (countMax <= 0)
            {
                yield break;
            }

            var count = random.Next(countMax);

            for (int i = 0; i < count; i++)
            {
                var pos = new Vector3(
                    random.NormallyDistributedSingle(_deviationX * _size, 0),
                    random.NormallyDistributedSingle(_deviationY * _size, 0),
                    random.NormallyDistributedSingle(_deviationZ * _size, 0)
                    );
                var d = pos.Length() / _size;
                var m = d * 2000 + (1 - d) * 7500;
                var t = random.NormallyDistributedSingle(4000, m, 1000, 40000);

                yield return(new Star(
                                 pos,
                                 StarName.Generate(random),
                                 t,
                                 m,
                                 _size
                                 ));
            }
        }
예제 #2
0
        public void Name()
        {
            Random r = new Random();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(StarName.Generate(r));
            }
        }
예제 #3
0
        protected internal override IEnumerable <Star> Generate(Random random)
        {
            int count = (int)(_size / _spacing);

            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < count; j++)
                {
                    for (int k = 0; k < count; k++)
                    {
                        yield return(new Star(new Vector3(
                                                  i * _spacing,
                                                  j * _spacing,
                                                  k * _spacing
                                                  ),
                                              StarName.Generate(random)
                                              ).Offset(new Vector3(-_size / 2, -_size / 2, -_size / 2)));
                    }
                }
            }
        }
예제 #4
0
    public void GenerateSolarSystem()
    {
        System.Random rand = new System.Random();

        //for generating a new solar system on the fly
        if (_solarSystem.Planets != null)
        {
            foreach (Planet p in _solarSystem.Planets)
            {
                Destroy(p.gameObject);
            }
            _solarSystem.Planets.Clear();
        }


        if (_solarSystem.Star != null)
        {
            Destroy(_solarSystem.Star.gameObject);
        }

        GameObject starGameObject = Instantiate(SolarSystemPrefabs.StarPrefab, transform.position, Quaternion.identity, this.transform);

        Star star = starGameObject.GetComponent <Star>();

        star.Name = StarName.Generate(rand);

        float starSize = Random.Range(Settings.MinStarSize, Settings.MaxStarSize) * Settings.SizeScale;

        star.Size = new Vector3(starSize, starSize, starSize);

        _solarSystem.Star = star;


        int   planetAmount       = Random.Range(Settings.MinPlanets, Settings.MaxPlanets);
        float lastPlanetDistance = 0f;

        for (int i = 0; i < planetAmount; i++)
        {
            //Instantiate planets
            float distance = Random.Range(Settings.MinDistanceBetween, Settings.MaxDistanceBetween) + lastPlanetDistance;
            lastPlanetDistance = distance;

            GameObject planetGameObject = Instantiate(SolarSystemPrefabs.PlanetPrefab,
                                                      star.transform.position + new Vector3(distance * Settings.SizeScale, distance * Settings.SizeScale, 0),
                                                      Quaternion.identity, this.transform);

            Planet planet = planetGameObject.GetComponent <Planet>();

            //set Planet Name
            planet.Name = StarName.Generate(rand);

            //set Planet Size
            float planetSize = Random.Range(Settings.MinPlanetSize, Settings.MaxPlanetSize) * ((distance / 10000) / Settings.SizeScale);
            planet.Size = new Vector3(planetSize, planetSize, planetSize);

            planet.OrbitPeriod = (distance / Settings.SizeScale) * 2;
            _solarSystem.Planets.Add(planet);

            //determine if planet has satellites orbiting it and instantiate them
            bool hasSatellite = Random.Range(Settings.ChanceOfSatellite, 10) <= Settings.ChanceOfSatellite;

            if (hasSatellite)
            {
                int satelliteAmount = Random.Range(Settings.MinSatellites, Settings.MaxPlanets);

                float lastSatelliteDistance = 0f;

                //instantiate satellite
                for (int j = 0; j < satelliteAmount; j++)
                {
                    float distanceToPlanet = (((distance * Settings.SizeScale) + lastSatelliteDistance) + planetSize) / 20;

                    lastSatelliteDistance = distanceToPlanet;

                    GameObject satelliteGameObject = Instantiate(SolarSystemPrefabs.SattelitePrefab,
                                                                 planetGameObject.transform.position + new Vector3(distanceToPlanet, 0, distanceToPlanet),
                                                                 Quaternion.identity, planet.transform);

                    Satellite satellite = satelliteGameObject.GetComponent <Satellite>();
                    satellite.OrbitPeriod = distanceToPlanet * planetSize * 100;
                    satellite.Orbiter     = planet;

                    //set Satellite name
                    satellite.Name = StarName.Generate(rand);

                    float satelliteSize = Random.Range(Settings.MinPlanetSize, Settings.MaxPlanetSize) * ((distanceToPlanet / 1000) / Settings.SizeScale);
                    satellite.Size = new Vector3(satelliteSize, satelliteSize, satelliteSize);

                    planet.Sattelites.Add(satellite);
                }
            }
        }

        _solarSystem.AllignPlanets();
    }
예제 #5
0
 public void UniqueNames()
 {
     var names = String.Join(",\n", StarName.Generate(new Random(), 1000));
 }
예제 #6
0
    public void GenerateGalaxy()
    {
        if (_galaxy.SolarSystems != null)
        {
            foreach (SolarSystem g in _galaxy.SolarSystems)
            {
                Destroy(g.gameObject);
            }

            _galaxy.SolarSystems.Clear();

            if (_galaxy.BlackHole != null)
            {
                Destroy(_galaxy.BlackHole.gameObject);
            }
        }


        GameObject blackHoleGameObject = Instantiate(GalaxyPrefabs.BlackHolePrefab, transform.position, Quaternion.identity, this.transform);
        BlackHole  blackHole           = blackHoleGameObject.GetComponent <BlackHole>();

        _galaxy.BlackHole = blackHole;

        //Set galaxy name
        System.Random rand = new System.Random();
        _galaxy.Name = StarName.Generate(rand);
        this.name    = _galaxy.Name;

        _galaxy.Size = new Vector2(Settings.Radius, Settings.Radius);

        int solarSystems = Random.Range(Settings.MinGalaxies, Settings.MaxGalaxies);

        List <Vector3> positions = Spiral.GenerateSpiral();

        //Generate solar systems of galaxy
        for (int i = 0; i < solarSystems; i++)
        {
            int     random = Random.Range(0, (Spiral.iterations * 2) - 1);
            Vector2 pos    = new Vector2(positions[random].x, positions[random].z) + Random.insideUnitCircle * Settings.Radius;

            while (CheckForGalaxies(pos))
            {
                pos = new Vector2(positions[random].x, positions[random].z) + Random.insideUnitCircle * Settings.Radius;
            }

            GameObject solarSystemGameObject = Instantiate(GalaxyPrefabs.SolarSystemPrefab, new Vector3(pos.x, pos.y, 0), Quaternion.identity, this.transform);

            SolarSystemGenerator solarSystemGenerator = solarSystemGameObject.GetComponent <SolarSystemGenerator>();
            SolarSystem          solarSystem          = solarSystemGameObject.GetComponent <SolarSystem>();

            solarSystem.Name           = StarName.Generate(rand);
            solarSystemGameObject.name = solarSystem.Name;

            solarSystem.Position = solarSystemGameObject.transform.position;

            _galaxy.SolarSystems.Add(solarSystem);

            solarSystemGenerator.GenerateSolarSystem();

            foreach (Planet p in solarSystem.Planets)
            {
                p.gameObject.SetActive(false);
            }
        }

        GetComponent <GalaxyNavigator>().Connect(_galaxy.SolarSystems);
    }