Esempio n. 1
0
    //This will determine where to set up more particle systems and create them in those positions
    private void Expansion()
    {
        int size = Random.Range(minSystemSize, maxSystemSize + 1);

        cluster = new List <NebulaSetup>(size);
        List <ChunkCoords> filled = new List <ChunkCoords>(size);
        ChunkCoords        c      = coords;

        filled.Add(c);
        int count     = 1;
        int failCount = 0;

        while (count < size && failCount < FAIL_LIMIT)
        {
            c = filled[Random.Range(0, filled.Count)];
            //pick a random adjacent coordinate
            float randomVal = Random.value;
            if (randomVal >= 0.5f)
            {
                c.x += randomVal >= 0.75f ? 1 : -1;
            }
            else
            {
                c.y += randomVal >= 0.25f ? 1 : -1;
            }
            c = c.Validate();

            bool alreadyExists = false;
            //this will check for nebulas already created in this group
            for (int i = 0; i < filled.Count; i++)
            {
                ChunkCoords check = filled[i];
                if (c == check)
                {
                    alreadyExists = true;
                    break;
                }
            }
            //if new coordinates have already been filled with nebula then pick a new coordinate
            if (alreadyExists)
            {
                failCount++;
                continue;
            }

            count++;
            filled.Add(c);
            NebulaSetup newNebula = Instantiate(this, transform.parent);
            cluster.Add(newNebula);
            newNebula.cluster = cluster;
            newNebula.SetColors(col1, col2);
            newNebula.SetThrusterReference(thrusterRef);
            newNebula.transform.position = ChunkCoords.GetCenterCell(c, EntityNetwork.CHUNK_SIZE);
            newNebula.shouldExpand       = false;
            EntityGenerator.FillChunk(c, true);
        }
    }