示例#1
0
    void GenerateNodes(TileRules nodetype, int amount, Dictionary <string, List <SpawnPoint> > spawns, int size)
    {
        List <SpawnPoint> availableSpawns = new List <SpawnPoint>();

        foreach (string key in spawns.Keys)
        {
            if (nodetype.CheckLimitations(key))
            {
                availableSpawns.AddRange(spawns[key]);
            }
        }
        for (int i = 0; i < amount; i++)
        {
            if (tempEdges.Count != 0 && nodetype.GetSelf() == tree)
            {
                tempEdges.Clear();
            }
            int        iterator = Random.Range(0, availableSpawns.Count);
            SpawnPoint spawn    = availableSpawns[iterator];
            GenerateArea(size, spawn.x, spawn.y, nodetype, true);
            availableSpawns.Remove(spawn);
            if (nodetype.GetSelf() == tree)
            {
                List <Vector3Int> actualEdges = new List <Vector3Int>();
                if (tempEdges.Count == 0)
                {
                    continue;
                }                                      // for(amount)
                foreach (Vector3Int selfPosition in tempEdges)
                {
                    if (nodes.GetTile(new Vector3Int(selfPosition.x + 1, selfPosition.y, 0)) == null)
                    {
                        actualEdges.Add(selfPosition);
                        continue;
                    }
                    else if (nodes.GetTile(new Vector3Int(selfPosition.x, selfPosition.y + 1, 0)) == null)
                    {
                        actualEdges.Add(selfPosition);
                        continue;
                    }
                    else if (nodes.GetTile(new Vector3Int(selfPosition.x - 1, selfPosition.y, 0)) == null)
                    {
                        actualEdges.Add(selfPosition);
                        continue;
                    }
                    else if (nodes.GetTile(new Vector3Int(selfPosition.x, selfPosition.y - 1, 0)) == null)
                    {
                        actualEdges.Add(selfPosition);
                        continue;
                    }
                }
                GameObject.Find("Grid").GetComponent <Environment>().AddForest(actualEdges);
            }
        }
    }
示例#2
0
 bool CheckTilesAt(int x, int y, Tilemap checkedMap, TileRules tester)
 {
     for (int z = -10; z <= 10; z++)
     {
         if (checkedMap.GetTile(new Vector3Int(x, y, z)) != null)
         {
             if (!tester.CheckLimitations((Tile)checkedMap.GetTile(new Vector3Int(x, y, z))))
             {
                 return(false);
             }
         }
     }
     return(true);
 }