Пример #1
0
 public Moon(CelestialType originalType)
 {
     this.originalType = originalType;
     density           = 4.0;
     minRadius         = 5;
     maxRadius         = 10;
     minDistance       = 500;
     maxDistance       = 800;
     hasWater          = originalType.hasWater;
     hasLava           = originalType.hasLava;
     hasIce            = originalType.hasIce;
 }
        /// <summary>
        /// Spawns a planet
        /// </summary>
        public void SpawnPlanet(int seed, CelestialBody host = null)
        {
            bool hasHost = host != null;

            System.Random random = new System.Random(seed);
            GameObject    go     = new GameObject();

            go.transform.parent = systemScale.transform;

            CelestialBody body;
            CelestialType type = hasHost ? CelestialType.GetRandomPlanetTypeExceptGas(random) : CelestialType.GetRandomPlanetType(random);

            if (type is CelestialType.GasPlanet)
            {
                body = new GasPlanet(controller, go, seed, host);
                int satellites = (int)Utility.GetRandomBetween(random, 1, 2.9);
                for (int i = 0; i < satellites; i++)
                {
                    SpawnPlanet(seed + 100 + i, body);
                }
            }
            else if (type is CelestialType.WaterPlanet)
            {
                body = new WaterPlanet(controller, go, seed, host);
                AddAtmosphere(body);
            }
            else if (type is CelestialType.RockPlanet)
            {
                body = new RockPlanet(controller, go, seed, host);
                AddAtmosphere(body);
            }
            else if (type is CelestialType.MoltenPlanet)
            {
                body = new MoltenPlanet(controller, go, seed, host);
                AddAtmosphere(body);
            }
            else
            {
                body = new IcePlanet(controller, go, seed, host);
                AddAtmosphere(body);
            }

            if (host == null && random.NextDouble() < 0.3)
            {
                GameObject rings = new GameObject("rings");
                rings.transform.parent = go.transform;
                var ringsScript = rings.AddComponent <PlanetRings>();
                ringsScript.Init(controller, body);
            }
            controller.celestials.Add(body);
        }
Пример #3
0
        public static CelestialType GetRandomPlanetTypeExceptGas(Random random)
        {
            CelestialType type = null;

            while (type == null)
            {
                type = GetRandomPlanetType(random);
                if (type is CelestialType.GasPlanet)
                {
                    type = null;
                }
            }
            return(type);
        }
        public CelestialBody(SystemController controller, GameObject gameObject, int seed, CelestialType type, CelestialBody host = null)
        {
            if (host != null)
            {
                type = new CelestialType.Moon(type);
            }
            gameObject.name = type.ToString();
            this.controller = controller;
            this.seed       = seed;
            this.type       = type;
            this.gameObject = gameObject;
            this.host       = host;
            System.Random random = new System.Random(seed);
            radius        = (int)Utility.GetRandomBetween(random, type.minRadius, type.maxRadius);
            density       = type.density;
            orbitDistance = Utility.GetRandomBetween(random, type.minDistance, type.maxDistance);

            mass            = (4.0 / 3.0) * Math.PI * Math.Pow(radius, 3.0) * density;
            oribtalVelocity = Utility.GetRandomBetween(random, 0.5, 3) / 360.0 * (type is CelestialType.Moon ? 100 : 1);
            orbitalOffset   = Utility.GetRandomBetween(random, 0, 360);
            rotationAxis    = Utility.RandomVector(random);
            rotationSpeed   = Utility.GetRandomBetween(random, 50, 100);
            UpdatePositionInSystem();
        }