Ejemplo n.º 1
0
    // This method creates the galaxy centre
    void CreateCentre()
    {
        // Spawn Centre
        for (int k = 0; k < (starsInCentreRounded + difference); k++)
        {
            Vector3 cartPosition = PositionMath.RandomPosition(minimumRadius, minimumRadius + (numberOfArms * 20));

            bool collision = PositionMath.CheckCollisions(minDistBetweenStars, cartPosition);

            int failCount = 0;

            if (collision != true)
            {
                // Data for Star
                Star starData = CreateStarData(starCount);
                starData.starPosition = cartPosition;
                starCount++;
                SetStarOwned(starData);

                // Object for Star
                CreateStarObject(starData, cartPosition);
                failCount = 0;
            }
            else
            {
                k--;
                failCount++;
            }
            if (failCount > numberOfStars)
            {
                break;
            }
        }
    }
Ejemplo n.º 2
0
    // This method creates a galaxy of stars and planet information.
    public void CreateGalaxy()
    {
        InitializeGalaxy();

        int failCount = 0;

        for (int i = 0; i < numberOfStars; i++)
        {
            Star starData = new Star("Star" + i, Random.Range(1, 10));
            //Debug.Log("Created " + starData.starName + " with " + starData.numberOfPlanets + " planets");
            CreatePlanetData(starData);

            Vector3 cartPosition = PositionMath.RandomPosition(minimumRadius, maximumRadius);

            bool collision = PositionMath.CheckCollisions(minDistBetweenStars, cartPosition);

            if (!collision == true)
            {
                GameObject starGO = SpaceObjects.CreateSphereObject(starData.starName, cartPosition, this.transform);
                starToObjectMap.Add(starData, starGO);
                failCount = 0;
            }
            else
            {
                i--;
                failCount++;
            }

            if (failCount > numberOfStars)
            {
                Debug.LogError("Could not fit all the stars in the galaxy. Distance between stars too big!");
                break;
            }
        }
    }
Ejemplo n.º 3
0
    // This method creats the galaxy arms
    void CreateArms()
    {
        // Spawn Arms
        for (int i = 0; i < numberOfArms; i++)
        {
            for (int j = 0; j < starsPerArmRounded; j++)
            {
                float armAngle  = (((Mathf.PI * 2f) / numberOfArms) * i);
                float starAngle = (((Mathf.PI * 2f) / starsPerArmRounded) * j);

                float angle    = PositionMath.SpiralAngle(armAngle, starAngle) + Random.Range(-Mathf.PI / (2 * numberOfArms), Mathf.PI / (2 * numberOfArms));
                float distance = (6 * numberOfArms) * Mathf.Sqrt(j + 1) + minimumRadius;

                Vector3 cartPosition = PositionMath.PolarToCart(distance, angle);

                int failCount = 0;

                bool collision = PositionMath.CheckCollisions(minDistBetweenStars, cartPosition);

                if (collision != true)
                {
                    // Data for Star
                    Star starData = CreateStarData(starCount);
                    starData.starPosition = cartPosition;
                    starCount++;
                    SetStarOwned(starData);

                    // Object for Star
                    CreateStarObject(starData, cartPosition);
                    failCount = 0;
                }
                else
                {
                    j--;
                    failCount++;
                }
                if (failCount > numberOfStars)
                {
                    break;
                }
            }
        }
    }
Ejemplo n.º 4
0
    public void CreateSpiralGalaxy()
    {
        float percent              = percentageStarsCentre / 100f;
        float starsInCentre        = percent * numberOfStars;
        int   starsInCentreRounded = Mathf.RoundToInt(starsInCentre);

        float starsPerArm        = (numberOfStars - starsInCentreRounded) / numberOfArms;
        int   starsPerArmRounded = Mathf.RoundToInt(starsPerArm);
        int   difference         = numberOfStars - (starsPerArmRounded * numberOfArms) - starsInCentreRounded;

        int starCount = 0;

        // Spawn Arms
        for (int i = 0; i < numberOfArms; i++)
        {
            for (int j = 0; j < starsPerArmRounded; j++)
            {
                Star starData = new Star("Star " + starCount, Random.Range(1, 10));
                starCount++;

                float armAngle  = (((Mathf.PI * 2f) / numberOfArms) * i);
                float starAngle = (((Mathf.PI * 2f) / starsPerArmRounded) * j);

                float angle    = PositionMath.SpiralAngle(armAngle, starAngle) + Random.Range(-Mathf.PI / (2 * numberOfArms), Mathf.PI / (2 * numberOfArms));
                float distance = (6 * numberOfArms) * Mathf.Sqrt(j + 1) + minimumRadius;

                Vector3 cartPosition = PositionMath.PolarToCart(distance, angle);

                int failCount = 0;

                bool collision = PositionMath.CheckCollisions(minDistBetweenStars, cartPosition);

                if (collision != true)
                {
                    GameObject starGO = SpaceObjects.CreateSphereObject(starData.starName, cartPosition, this.transform);
                    failCount = 0;
                }
                else
                {
                    j--;
                    failCount++;
                }
                if (failCount > numberOfStars)
                {
                    break;
                }
            }
        }

        // Spawn Centre
        for (int k = 0; k < starsInCentreRounded + difference; k++)
        {
            Star starData = new Star("Star " + starCount, Random.Range(1, 10));
            starCount++;
            Vector3 cartPosition = PositionMath.RandomPosition(minimumRadius, minimumRadius + (numberOfArms * 20));

            bool collision = PositionMath.CheckCollisions(minDistBetweenStars, cartPosition);

            int failCount = 0;

            if (collision != true)
            {
                GameObject starGO = SpaceObjects.CreateSphereObject(starData.starName, cartPosition, this.transform);
                failCount = 0;
            }
            else
            {
                k--;
                failCount++;
            }
            if (failCount > numberOfStars)
            {
                break;
            }
        }
    }