Пример #1
0
    void BuildPaths(Chunk node)//recursive DFS
    {
        if (node.visited)
        {
            return;
        }
        Chunk[] neighbors = new Chunk[8];
        int     ctr       = 0;

        for (int x = -1; x <= 1; x++)
        {
            for (int y = -1; y <= 1; y++)
            {
                for (int z = -1; z <= 1; z++)
                {
                    float chanceOfVisit = (float)rand.NextDouble();
                    if (chanceOfVisit >= .75 && existingChunks.ContainsKey(node.coord + new Vector3Int(x, y, z)))
                    {
                        neighbors[ctr] = existingChunks[node.coord + new Vector3Int(x, y, z)];
                    }
                }
            }
        }
        node.visited = true;
        for (int j = 0; neighbors[j] != null; j++)
        {
            int wormLength    = (int)minWormLength + (int)((float)rand.NextDouble() * (maxWormLength - minWormLength));
            int wormRadius    = (int)minWormRadius + (int)((float)rand.NextDouble() * (maxWormRadius - minWormRadius));
            var walkableWorms = new PerlinWorm(node.data.dataWidth * 3, wormRadius, new Vector3((node.data.dataWidth / 2) + node.coord.x, (node.data.dataHeight / 2) + node.coord.y, (node.data.dataDepth / 2) + node.coord.z),
                                               Mathf.Sin(wormLength), Mathf.Cos(wormRadius), Mathf.Tan(wormLength + wormRadius));
            walkableWorms.WalkableWorms(existingChunks, node.coord, neighbors[j].coord, new Vector3(chunkSize / 2, chunkSize / 2, chunkSize / 2), neighbors[j].coord * chunkSize);
            BuildPaths(neighbors[j]);
        }
    }
Пример #2
0
    void WormifyChunks()
    {
        foreach (Chunk c in chunks)
        {
            //number of worms (1, maxWorms)
            int numWorms = (int)((float)rand.NextDouble() * (maxWorms - 1)) + 1;
            Debug.Log("wormSettings:" + numWorms);
            for (int i = 0; i < numWorms; i++)
            {
                int wormLength = (int)minWormLength + (int)((float)rand.NextDouble() * (maxWormLength - minWormLength));
                int wormRadius = (int)minWormRadius + (int)((float)rand.NextDouble() * (maxWormRadius - minWormRadius));
                var worm       = new PerlinWorm(wormLength, wormRadius, new Vector3((c.data.dataWidth / 2) + c.coord.x, (c.data.dataHeight / 2) + c.coord.y, (c.data.dataDepth / 2) + c.coord.z),
                                                Mathf.Sin(wormLength), Mathf.Cos(wormRadius), Mathf.Tan(wormLength + wormRadius));
                worm.Wormify(existingChunks, c.coord, new Vector3(chunkSize / 2, chunkSize / 2, chunkSize / 2), c.coord * chunkSize);
            }
        }

        for (int i = 0; i < chunks.Count; i++)
        {
            if (!chunks[i].visited)
            {
                BuildPaths(chunks[i]);
            }
        }
    }