Ejemplo n.º 1
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.º 2
0
    public void CreateSpiralGalaxy()
    {
        Random.InitState(seedNumber);

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

        for (int i = 0; i < numberOfArms; i++)
        {
            for (int j = 0; j < starsPerArmRounded; j++)
            {
                Star  starData  = new Star("Star " + (j + (starsPerArm * i)), Random.Range(1, 10));
                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 = (4 * numberOfArms) * Mathf.Sqrt(j + 1) + minimumRadius;

                Vector3 cartPos = PositionMath.PolarToCart(distance, angle);
                SpaceObjects.CreateSphereObject(starData.starName, cartPos, this.transform);
            }
        }
    }
Ejemplo n.º 3
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;
            }
        }
    }