Beispiel #1
0
    public void StartGenerator(int x, int y, int type, int size)
    {
        for (int i = x; i < size + x; i++)
        {
            for (int j = y; j < size + y; j++)
            {
                WorldTile   wt        = GetTile(i, j);
                WorldTile[] neighbors = wt.GetNeighbors();
                int         count     = 0;
                //                Debug.Log("X: " + wt.x + "Y: " + wt.y + " Type:" + (int)wt.type);

                foreach (WorldTile w in neighbors)
                {
                    if ((int)w.type == (int)wt.type)
                    {
                        count++;
                    }
                }
                if ((int)wt.type == type)
                {
                    if (count > 1)
                    {
                        regions[type].grid.SetTile(new Vector3Int(i, j, type * -1), regions[type].tile);

                        if (j - 1 > 0)
                        {
                            regions[type].grid.SetTile(new Vector3Int(i, j - 1, type * -1), regions[type].tile);
                        }
                        if (j + 1 < mapHeight)
                        {
                            regions[type].grid.SetTile(new Vector3Int(i, j + 1, type * -1), regions[type].tile);
                        }

                        if (i - 1 > 0)
                        {
                            regions[type].grid.SetTile(new Vector3Int(i - 1, j, type * -1), regions[type].tile);
                        }

                        if (i + 1 < mapHeight)
                        {
                            regions[type].grid.SetTile(new Vector3Int(i + 1, j, type * -1), regions[type].tile);
                        }
                    }
                }



                //if ((int)wt.type == type && type > 0)
                //{
                //    regions[type].grid.SetTile(new Vector3Int(i, j, 0), regions[type].tile);
                //    regions[type - 1].grid.SetTile(new Vector3Int(i, j, 0), regions[type].tile);

                //}
                //else if ((int)wt.type == type)
                //{
                //    regions[type].grid.SetTile(new Vector3Int(i, j, 0), regions[type].tile);

                //}
            }
        }
    }