Init() public method

public Init ( ) : void
return void
Exemplo n.º 1
0
        void CreatePlayers()
        {
            List <Planet> planetsInSystem = new List <Planet>();
            int           idCounter       = 0;

            //Create player and subscribe for events
            Planet planet = AssetsLibrary.Library_Prefabs.CreatePlanetPrefab();

            planet.OnCreateProjectile    += CreateProjectile;
            m_OnPauseStateChanged        += planet.PauseUpdate;
            m_OnGameFinished             += planet.PauseUpdate;
            m_InputManager.OnPlayerShoot += planet.Shoot;
            m_Player = planet;

            planet.Init(GetPlayerRandomHP(),
                        AssetsLibrary.Library_Sprites.GetRandomPlayerSprite(),
                        GetRandomOrbitPeriod(),
                        AssetsLibrary.Library_Colors.PlayerHightlightColor,
                        GameSettings.ProjectileStats[Random.Range(0, GameSettings.ProjectileStats.Length)],
                        GameSettings.PlanetScaleToWeightMltp,
                        true,
                        idCounter++);

            //Add planet to list of planets for further orbit processing
            planetsInSystem.Add(planet);

            //Create enemies
            m_TotalEnemies   = Random.Range(GameSettings.MinEnemiesAmount, GameSettings.MaxEnemiesAmount + 1);
            m_CurrentEnemies = m_TotalEnemies;
            for (int i = 0; i < m_TotalEnemies; i++)
            {
                planet = AssetsLibrary.Library_Prefabs.CreatePlanetPrefab();
                planet.OnCreateProjectile += CreateProjectile;

                //Subscribe for pause event
                m_OnPauseStateChanged += planet.PauseUpdate;
                m_OnGameFinished      += planet.PauseUpdate;

                planet.Init(GetEnemyRandomHP(),
                            AssetsLibrary.Library_Sprites.GetRandomEnemySprite(),
                            GetRandomOrbitPeriod(),
                            AssetsLibrary.Library_Colors.EnemyHightlightColor,
                            GameSettings.ProjectileStats[Random.Range(0, GameSettings.ProjectileStats.Length)],
                            GameSettings.PlanetScaleToWeightMltp,
                            false,
                            idCounter++,
                            GetRandomScale());

                //Add planet to list of planets for further orbit processing
                planetsInSystem.Add(planet);

                //Add planet to physics processing
                PhysicsController.AddAttractor(planet);

                //Add planet to AI processing
                m_AIManager.AddObjectToProcessing(planet);
            }

            ApplyOrbits(planetsInSystem);
        }
Exemplo n.º 2
0
    //게임 시작. 무기 선택 부터 시작.
    public void GameStart()
    {
        gameState = DefEnum.GameState.SELECT_WEAPON;

        if (ingameUI == null)
        {
            ingameUI = UIManager.Instance.LoadUI("IngameUI").GetComponent <IngameUI>();
        }
        else
        {
            ingameUI.gameObject.SetActive(true);
        }

        planet.Init();
        currentScore     = 0;
        currentResources = 0;
        upgradeCost      = 0;
        upgradeLV        = 1;
        SetMainWeaponID();
        GetUpgradeCost();

        ingameUI.SetScore(currentScore);
        ingameUI.SetResources(currentResources, upgradeCost);

        SpawnManager.Instance.Init();
        EffectManager.Instance.InitIngameEffects();

        //시작할 때 무기 선택 창 열기.
        UIManager.Instance.LoadPopupUI("WeaponUI");
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        testPlanet = (Planet)Instantiate(planetPrefab, new Vector3(0f, 0f, 0f), Quaternion.identity);
        Camera.main.orthographicSize = 64f;

        viewHeight = Camera.main.orthographicSize * 2f;
        // viewWidth = Camera.main.aspect * viewHeight;
        viewWidth = viewHeight * 2f;

        testPlanet.Init(this);
    }
Exemplo n.º 4
0
    void SpawnPlanet(string name, Vector2 coordinates, int type, int position)
    {
        //TODO: planet name

        GameObject planetObj = Instantiate(planetTypes[type]);

        planetObj.transform.position = new Vector3(coordinates.x * (position * 20 + 60), 0, coordinates.y * (position * 20 + 60));
        Planet planet = planetObj.GetComponent <Planet>();

        planet.Init(this.currentSystemName, name, (position * 20 + 60), minimap);
        this.spawnedPlanets.Add(planetObj);
    }
Exemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        Planet p = (target as Planet);

        if (GUILayout.Button("Generate"))
        {
            p.Init();
            p.Generate();
        }
        if (GUILayout.Button("Simplify"))
        {
            p.Simplify(SceneView.lastActiveSceneView.camera.transform.position);
        }
    }
Exemplo n.º 6
0
    void SpawnPlanet(float y, bool isFirstSpawn = false)
    {
        // Get new planet from pool
        Planet planet = prefabPool.GetPlanet().GetComponent <Planet>();

        // Initialize planet with material/type
        planet.Init(materials[Random.Range(0, materials.Length)], this);

        // Assign position
        planet.gameObject.transform.position = new Vector3(xPosition, y, 0);

        // Add it to list
        planets.Add(planet);

        // Play sound
        if (!isFirstSpawn)
        {
            audioManager.PlaySFX(AudioClips.SFX_PLANET_SPAWN);
        }
    }
Exemplo n.º 7
0
        protected override void UpgradeClass(
            ITemplateManager templateManager,
            SpaceBody spaceBody,
            Mapping upgradeMapping)
        {
            int    colourSettingsRandom = UnityEngine.Random.Range(0, planetSettings.colourSettings.Length);
            int    shapeSettingsRandom  = UnityEngine.Random.Range(0, planetSettings.shapeSettings.Length);
            Planet planet = spaceBody.gameObject.AddComponent <Planet>();

            planet.Init(planetSettings.shapeSettings[shapeSettingsRandom], planetSettings.colourSettings[colourSettingsRandom], planetSettings.resolution);
            var graviatation = templateManager.SetUpGravitation(spaceBody);

            spaceBody.Mass += 10;
            var satelliteManager = spaceBody.GetComponent <SatelliteManager>();

            satelliteManager.MaxCountSattelites = 2;
            spaceBody.gameObject.layer          = LayerHelper.Planet;
            spaceBody = SpinPlanet(spaceBody);
            spaceBody.mappingUpgradeSpaceObject = upgradeMapping;
        }
Exemplo n.º 8
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _pixel = new Texture2D(_graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _pixel.SetData(new[] { Color.White });
            DisplayHelper.Init(Content, _pixel);

            _planet = new Planet(PlanetSimulationConfig.DefaultConfig);
            _planet.Init();

            _debugFont = Content.Load <SpriteFont>("DebugFont");

            _graphics.PreferredBackBufferWidth  = (int)(_planet.Config.Width * DRAW_SCALE);
            _graphics.PreferredBackBufferHeight = (int)(_planet.Config.Height * DRAW_SCALE) + (int)_debugFont.MeasureString("X").Y *4;
            _graphics.ApplyChanges();

            SpriteBatchExtensions.GraphicsDevice = GraphicsDevice;
        }
Exemplo n.º 9
0
        private void Start()
        {
            for (int i = 0; i < planetsData.Count; i++)
            {
                Planet.PlanetData pd = planetsData[i];

                GameObject gameObjectQueRecienInstancie = Instantiate(planetPrefab).gameObject;

                gameObjectQueRecienInstancie.AddComponent <TiposBasicosDeDatos>();

                Planet p = gameObjectQueRecienInstancie.GetComponent <Planet>();
                p.Init(pd);

                generatedPlanets.Add(p);

                Debug.Log("padre del planeta recien instanciado: " + gameObjectQueRecienInstancie.transform.parent);

                gameObjectQueRecienInstancie.transform.parent = FindObjectOfType <Camera>().transform;

                //go.transform.parent = gameObject.transform;
            }
            //if is dead and far away from player
            //Destroy(gameObject, 1);
        }
Exemplo n.º 10
0
    private void Start()
    {
        foreach (var s in suns)
        {
            s.Init();
        }

        moon.Init();

        moon.gameObject.SetActive(false);
        var forward = moon.transform.forward;
        var pos     = moon.transform.position;

        planets = new NativeArray <PlanetData>(simSize, Allocator.Persistent);
        var planetsData = new PlanetData[simSize];

        for (int i = 0; i < planetsData.Length; i++)
        {
            var data = new PlanetData();
            data.velocity = forward * (moon.startSpeed + Random.Range(-startSpeedRandomness, startSpeedRandomness));
            data.mass     = moon.mass + Random.Range(-massRandomness, massRandomness);
            var p = pos + Vector3.ClampMagnitude(new Vector3(Random.Range(-spread.x, spread.x), Random.Range(-spread.y, spread.y), Random.Range(-spread.z, spread.z)), 25);

            data.position  = p;
            data.size      = Random.Range(minSize, maxSize);
            planetsData[i] = data;
        }
        planets.CopyFrom(planetsData);


        if (useParticles)
        {
            particles = new ParticleSystem.Particle[simSize];
            for (int i = 0; i < particles.Length; i++)
            {
                var part = particles[i];
                part.rotation3D = new Vector3(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360));
                particles[i]    = part;
            }
            particlesNative = new NativeArray <ParticleSystem.Particle>(particles, Allocator.Persistent);
            sunsNative      = new NativeArray <PlanetData>(suns.Length, Allocator.Persistent);
            for (int i = 0; i < suns.Length; i++)
            {
                sunsNative[i] = suns[i].data;
            }
        }
        else
        {
            moons = new List <Planet>(simSize);


            List <Transform> planetTransforms = new List <Transform>();

            for (int i = 0; i < simSize; i++)
            {
                var m = Instantiate(moon);
                m.data = planetsData[i];
                m.Init();
                if (useJob)
                {
                    planetTransforms.Add(m.transform);
                }
                moons.Add(m);
            }
            planetsAccess = new TransformAccessArray(planetTransforms.ToArray());
        }
    }
Exemplo n.º 11
0
    void SpawnShuttleParts(Planet planet)
    {
        currentPickups = 0;
        //initialize mesh (Denis stuff)
        //Place Pickups
        //Place shuttle
        //initialize planet variables
        // Place shuttle

        /*RaycastHit hit;
         * Vector3 dir = Random.insideUnitCircle.normalized;
         * dir.z = dir.x;
         * dir.x = 0;
         * if (Physics.Raycast(planet.transform.position, dir, out hit, Mathf.Infinity, layerMask))
         * {*/
        int value = shuttle.shuttleParts.Count;
        var fire  = shuttle.fireParticleSystem.main;

        fire.startLifetime = 5.0f * value;
        var smoke = shuttle.smokeParticleSystem.main;

        smoke.startLifetime = 5.0f * value;

        shuttle.transform.position = planet.crashPoint;
        shuttle.transform.rotation = Quaternion.identity;
        shuttle.gameObject.transform.LookAt(planet.transform.position, Vector3.Cross(planet.transform.up, (planet.transform.position - shuttle.gameObject.transform.position).normalized));
        shuttle.transform.Translate(shuttleObjectsDistance, 0, 0, Space.World);
        //}
        planet.Init(-9.7f);


        List <Vector3> pickupPositions = new List <Vector3>();

        pickupPositions.Add(new Vector3(shuttle.transform.position.x, shuttle.transform.position.y, shuttle.transform.position.z));
        int placingTry    = 0;
        int maxIterations = 5;

        RaycastHit hit;
        int        layerMask = 1 << 10;

        for (int i = 0; i < shuttle.shuttleParts.Count; i++)
        {
            RaycastHit partPlanetHit;
            Vector3    dir = Random.insideUnitCircle.normalized;
            dir.z = dir.x;
            dir.x = 0;
            //hits ONLY planet
            layerMask = 1 << 10;
            //this sucks!!
            Physics.Raycast(planet.transform.position, dir, out partPlanetHit, Mathf.Infinity, layerMask);
            float planetCircumference = 2 * partPlanetHit.distance * Mathf.PI;
            float placingDistance     = planetCircumference / ((float)shuttle.shuttleParts.Count * 2);


            placingTry = 0;
            while (placingTry < maxIterations)
            {
                dir   = Random.insideUnitCircle.normalized;
                dir.z = dir.x;
                dir.x = 0;
                bool canPlace = true;

                if (Physics.Raycast(planet.transform.position, dir, out partPlanetHit, Mathf.Infinity, layerMask))
                {
                    for (int p = 0; p < pickupPositions.Count; p++)
                    {
                        if (Vector3.Distance(pickupPositions[p], partPlanetHit.point) < placingDistance)
                        {
                            //is too close: jump back to while and increase placing try
                            placingTry++;
                            canPlace = false;
                            p        = pickupPositions.Count;
                        }
                    }
                }
                if (canPlace)
                {
                    placingTry = maxIterations;
                }
            }

            Debug.DrawRay(planet.transform.position, dir * 500, Color.yellow, 60);
            placingTry = 0;
            // Instantiate the part
            GameObject shuttlePart    = shuttle.shuttleParts[i];
            Transform  spawnTransform = shuttlePart.transform.Find("Spawnpoint");
            PickUp     pickUp         = spawnTransform.gameObject.AddComponent <PickUp>();
            int        index          = new int();
            index        = i;
            pickUp.index = index;

            shuttlePart.transform.SetParent(null);
            shuttlePart.transform.localScale         = Vector3.one * partScaleFactor;
            pickUp.GetComponent <Collider>().enabled = true;

            Vector3    up             = partPlanetHit.point - planet.transform.position;
            Quaternion lookRotation   = Quaternion.LookRotation(new Vector3(-1, 0, 0), up);
            Quaternion offsetRotation = lookRotation * Quaternion.Inverse(spawnTransform.rotation);
            shuttlePart.transform.rotation = offsetRotation * shuttlePart.transform.rotation;


            Vector3 offsetPosition = partPlanetHit.point - spawnTransform.position;
            shuttlePart.transform.position += offsetPosition;
            shuttlePart.transform.Translate(shuttleObjectsDistance, 0, 0, Space.World);

            pickupPositions.Add(new Vector3(shuttlePart.transform.position.x, shuttlePart.transform.position.y, shuttlePart.transform.position.z));
        }

        StartCoroutine(SpawnPrefabForTime(impactParticleSystem, shuttle.transform.position, shuttle.transform.rotation));
    }
Exemplo n.º 12
0
    /// <summary>
    /// Instancia os planetas a partir de um array de nomes.
    /// </summary>
    void SetPlanets()
    {
        Debug.Log("Criando o mapa...");

        Planet spawningPlanet = null;

        int planetsRows = 0;
        int planetsCols = 0;

        float result = Mathf.Sqrt(words.Length);

        if (result % 1 == 0)
        {
            planetsRows = (int)result;
            planetsCols = (int)result;
        }
        else
        {
            Debug.LogError("Numero de planetas impossivel de criar grade quadrada. Numero de planetas = " + words.Length);
            return;
        }

        for (int i = 0; i < planetsRows; i++)
        {
            for (int j = 0; j < planetsCols; j++)
            {
                float dist = planetsDistance / 4;

                spawningPlanet = Instantiate(planetPrefabs[(int)Random.Range(0, planetPrefabs.Length)],
                                             new Vector3(j * planetsDistance + Random.Range(-dist, dist), i * planetsDistance + Random.Range(-dist, dist), 0),
                                             Quaternion.identity, planetsParent).GetComponent <Planet>();


                spawningPlanet.gameObject.name = words[planets.Count];
                planets.Add(spawningPlanet);

                spawningPlanet.Init(spawningPlanet.gameObject.name, null, null, null, this);
            }
        }

        // Adiciona os vizinhos de cada planeta.
        List <Planet> neighbors = new List <Planet>();

        for (int i = 0; i < planets.Count; i++)
        {
            if (i % planetsCols != 0)
            {
                neighbors.Add(planets[i - 1]);
            }
            else
            {
                neighbors.Add(null);
            }

            if (i + planetsCols < planets.Count)
            {
                neighbors.Add(planets[i + planetsCols]);
            }
            else
            {
                neighbors.Add(null);
            }

            if ((i + 1) % planetsCols != 0)
            {
                neighbors.Add(planets[i + 1]);
            }
            else
            {
                neighbors.Add(null);
            }

            if (i - planetsCols >= 0)
            {
                neighbors.Add(planets[i - planetsCols]);
            }
            else
            {
                neighbors.Add(null);
            }

            planets[i].SetNeighbors(neighbors);

            neighbors = new List <Planet>();
        }

        // Rotaciona o conjunto de planetas.
        planetsParent.transform.Rotate(new Vector3(0, 0, planetsDistAngle));

        // Adiciona os itens dos planetas
        for (int i = 0; i < planets.Count; i++)
        {
            int       id  = Random.Range(0, 3);
            Variation var = Variation.blue;

            if (id == 0)
            {
                var = Variation.red;
            }
            else if (id == 1)
            {
                var = Variation.green;
            }

            if (i % 2 == 0)
            {
                planets[i].SetItem(ItemType.demand, var, 100);
            }
            else
            {
                planets[i].SetItem(ItemType.good, var, 100);
            }
        }

        SetConnectionsGraphics(planetsCols);

        activePlanet = planets[0];
    }
Exemplo n.º 13
0
        public static PSystem GenerateStarsystem(int numberOfPlanets, int ID, GalaxyManager galaxyManager, LocalIDManager idManager, GalaxyRegistrationManager rm, LocatorService ls)
        {
            bool hasPort = false;

            // Add sun

            float size         = r.Next(100, 255) / 100f;
            float mass         = r.Next(50, 255) / 10f;
            float innerGravity = mass / 1875f;
            float outerGravity = innerGravity / 6f;

            var s    = (SunTypes[])Enum.GetValues(typeof(SunTypes));
            int type = r.Next(0, s.Length);

            var star = new Star(size, mass, innerGravity, outerGravity, s[type]);

            var system = new PSystem(star, ID, ls);

            system.AreaSize = baseBorder + r.Next(0, borderVariation);


            // Add Name
            system.AreaName = NameProvider.GetRandomName();


            rm.RegisterObject(system);


            for (int i = 0; i < numberOfPlanets; i++)
            {
                Planet planet;
                bool   SatisfiedWithResults = false;
                int    numAttempts          = MaxAttempts;
                system.IsCluster = false;
                int clusterType = 0;



                planet = new Planet(system, 0, ls);

                planet.AreaName = system.AreaName + " " + ToRoman(i + 1);

                if (r.Next(0, 101) > (100 - chanceOfCluster)) // Chance for planets to cluster
                {
                    system.IsCluster = true;
                    clusterType      = r.Next(0, clusterRadii.Count()); // Get which type of cluster
                }

                planet.Init(i, moonChance, minDistance, incrementOfOrbit, variationOfOrbit, 0,
                            r.Next());
                SatisfiedWithResults = !CheckForCollisions(system, planet); // True if we find any collisions.



                while (!SatisfiedWithResults)// While we're not content with the generation
                {
                    planet.Init(i, moonChance, minDistance, incrementOfOrbit, variationOfOrbit, 0,
                                r.Next());

                    SatisfiedWithResults = !CheckForCollisions(system, planet); // True if we find any collisions.

                    if (SatisfiedWithResults && system.IsCluster && i > 0)
                    {
                        SatisfiedWithResults = CheckForCollisions(system, planet, clusterRadii[clusterType]); // Cluster planets
                    }

                    numAttempts++;

                    if (numAttempts >= MaxAttempts && !system.IsCluster)
                    {
                        break; // Breaks out of infinite pass if it ever occurs
                    }
                    else if (numAttempts >= MaxAttempts && system.IsCluster)
                    {
                        i = 0; // Reset the whole operation because there's a bad system being generated.
                        foreach (Planet pll in system.GetPlanets())
                        {
                            system.RemovePlanet(pll);
                            rm.DeRegisterObject(pll);
                        }
                        break;
                    }
                }

                if (SatisfiedWithResults == false) // Don't add a colliding planet!
                {
                    //Logger.log(Log_Type.WARNING, "Skipped adding a planet due to MaxAttempts being too much");
                    continue;
                }
                planet.Id = idManager.PopFreeID();
                system.AddPlanet(planet);
                planet.ParentAreaID = system.Id;
                rm.RegisterObject(planet);

                if (system.AreaSize < planet.Distance - baseBorder) // If we're skinny, throw in a little extra space
                {
                    system.AreaSize = planet.Distance + baseBorder + r.Next(0, borderVariation);
                }
            }


            foreach (Planet p in system.GetPlanets())
            {
                _generateMoons(system, p, galaxyManager, idManager, rm, ls);
            }

            foreach (Planet m in system.GetMoons())
            {
                if (system.AreaSize < ls.AreaLocator.GetArea(m.IDToOrbit).Distance + m.Distance + baseBorder)
                {
                    // If we're skinny, throw in a little extra space
                    system.AreaSize = ls.AreaLocator.GetArea(m.IDToOrbit).Distance + m.Distance + baseBorder + r.Next(0, borderVariation);
                }
            }

            // Port Generation
            if (r.Next(0, 100) > 100 - portChance && !hasPort)
            {
                if (system.MoonCount > 0)
                {
                    for (int i = 0; i < system.MoonCount; i++)
                    {
                    }
                    int cr          = r.Next(0, system.MoonCount + 1); // Finds moon to turn into port.
                    int currentMoon = 0;                               // Used to get the moon

                    foreach (Planet m in system.GetMoons())
                    {
                        if (currentMoon == cr)
                        {
                            Planet moonToPort = m;
                            moonToPort.ParentAreaID = system.Id;
                            system.RemoveMoon(m);
                            rm.DeRegisterObject(m);

                            Port por = new Port(idManager.PopFreeID(), moonToPort, system.AreaName, ShipStatManager.StatShipList.ToList <ShipStats>(), ls); // Converts a moon into a port.
                            system.AddPort(por);
                            rm.RegisterObject(por);

                            hasPort = true;
                            break;
                        }
                        currentMoon++;
                    }
                }
            }


            return(system);
        }