コード例 #1
0
    public static ChunkCoords GetNearbyEmptyChunk()
    {
        int         range = 0;
        ChunkCoords pos   = new ChunkCoords(IntPair.zero, EntityNetwork.CHUNK_SIZE);

        while (range < int.MaxValue)
        {
            for (pos.x = -range; pos.x <= range;)
            {
                for (pos.y = -range; pos.y <= range;)
                {
                    ChunkCoords validCC = pos.Validate();
                    if (!instance.ChunkExists(validCC) || !instance.Chunk(validCC))
                    {
                        return(validCC);
                    }
                    pos.y += pos.x <= -range || pos.x >= range ?
                             1 : range * 2;
                }
                pos.x += pos.y <= -range || pos.y >= range ?
                         1 : range * 2;
            }
            range++;
        }
        return(ChunkCoords.Invalid);
    }
コード例 #2
0
    public static List <Entity> SpawnEntityInChunkNorthOfCamera(SpawnableEntity se, EntityData?data = null)
    {
        Vector3     cameraPos = Camera.main.transform.position;
        ChunkCoords cc        = new ChunkCoords(cameraPos, EntityNetwork.CHUNK_SIZE);

        cc.y++;
        cc = cc.Validate();
        return(SpawnEntityInChunk(se, data, cc));
    }
コード例 #3
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);
        }
    }
コード例 #4
0
    public static List <Entity> SpawnEntityInChunkNorthOfCamera(string entityName)
    {
        Vector3     cameraPos = Camera.main.transform.position;
        ChunkCoords cc        = new ChunkCoords(cameraPos, EntityNetwork.CHUNK_SIZE);

        cc.y++;
        cc = cc.Validate();
        SpawnableEntity se = GetSpawnableEntity(entityName);

        return(SpawnEntityInChunk(se, null, cc));
    }