Esempio n. 1
0
    void LoadPlanets()
    {
        var Planets = GameManager.game.sData.PlanetsData;

        //colliders = new List<BoxCollider2D>();

        print("planet count: " + Planets.Count);

        foreach (var currentPlanet in Planets.Values)
        {
            GameObject TravelableObject;
            GameObject currentPlanetPrefab;

            currentPlanetPrefab = Resources.Load(@"Travelables\" + Prefabs[currentPlanet.PreFabNum]) as GameObject;

            //Instantiate
            TravelableObject = Instantiate(currentPlanetPrefab, currentPlanet.Position, Quaternion.identity);

            //Initialize script
            Travelable Script = TravelableObject.GetComponent <Travelable>();
            Script.Initialize(currentPlanet.Name, difficulty);
            Script.WasVisited = currentPlanet.wasVisited;

            //Deactivate collider
            TravelableObject.GetComponentInChildren <BoxCollider2D>().enabled = false;
        }
    }
Esempio n. 2
0
    //Spawn a random number of travelables in random positions
    void SpawnTravelables()
    {
        float rightBound = 15.0f;
        float leftBound  = -13.0f;
        float topBound   = 7.00f;
        float botBound   = -6.0f;

        var SolarSystem = GameManager.game.sData;

        colliders = new List <BoxCollider2D>();

        for (int i = 0; i < NumberOfTravelables; i++)
        {
            GameObject TravelableObject;
            GameObject currentPlanet;
            PlanetData newPlanet = new PlanetData();

            string currentName = GetUniqueRandomName();

            SolarSystem.UsedNames.Add(currentName);

            int prefabNum = Random.Range(0, 7);
            currentPlanet = Resources.Load(@"Travelables\" + Prefabs[prefabNum]) as GameObject;

            //Generate random position
            float   x        = Random.Range(leftBound, rightBound);
            float   y        = Random.Range(topBound, botBound);
            Vector2 position = new Vector2(x, y);


            TravelableObject     = Instantiate(currentPlanet, position, Quaternion.identity);
            TravelableObject.tag = "Anomaly";
            Travelable    Script       = TravelableObject.GetComponent <Travelable>();
            BoxCollider2D currCollider = TravelableObject.GetComponentInChildren <BoxCollider2D>();

            //Initialize Travelable Object's Traits
            Script.Initialize(SolarSystem.UsedNames[i], difficulty);

            if (collisionDetected(currCollider))
            {
                SolarSystem.UsedNames.Remove(currentName); //Remove currentName from used names
                Names.Add(currentName);                    //re-add currentName to unused name pool upon destruction
                Destroy(TravelableObject);
                i = i - 1;                                 //Redo this iteration.
            }
            else
            {
                colliders.Add(currCollider);

                //Save current planet in game manager
                newPlanet.Name = currentName;
                //print("newPlanet.Name " + newPlanet.Name);
                print(newPlanet.Name);
                newPlanet.PreFabNum  = prefabNum;
                newPlanet.Difficulty = difficulty;
                newPlanet.Position   = position;
                newPlanet.Tag        = (string)TravelableObject.tag;
                newPlanet.wasVisited = false;
                SolarSystem.PlanetsData[newPlanet.Name] = newPlanet;
            }
        }

        DeactivateBoxColliders();

        float xGate = Random.Range(15.8f, 16.8f);
        float yGate = Random.Range(-5.5f, 9.0f);

        Vector3 gatePos = SetGatePosition(new Vector3(xGate, yGate, 0f));

        Gate.transform.position = gatePos;

        Gate.GetComponent <SpriteRenderer>().enabled = true;
        GameManager.game.sData.gatePosition          = gatePos;
    }