Esempio n. 1
0
    private IEnumerator InitWorld_Prim()
    {
        WorldTile.SetTileColors(
            new Dictionary <WorldTileType, Color>()
        {
            { WorldTileType.Undefined, new Color(0f, 0f, 0f) },
            { WorldTileType.Room, new Color(0.8f, 0.9f, 0.8f) },
            { WorldTileType.Wall, new Color(0.2f, 0.2f, 0.2f) },
            { WorldTileType.Pillar, new Color(0.1f, 0.1f, 0.1f) },
            { WorldTileType.WallOpen, new Color(0.8f, 0.9f, 0.8f) },

            { WorldTileType.WallA, new Color(0.2f, 0.1f, 0.1f) },
            { WorldTileType.WallB, new Color(0.1f, 0.2f, 0.1f) },
        }
            );

        // initialize the board with tiles
        for (int row = 0; row < _numRows; row++)
        {
            for (int col = 0; col < _numCols; col++)
            {
                WorldTileConfig tileConfig = _tileSeed.GetTileConfig(col, row);
                WorldTileType   tileType   = tileConfig.TileType;
                if (_numCols > 5)
                {
                    if (tileType == WorldTileType.WallA)
                    {
                        tileType = WorldTileType.Wall;
                    }
                    else if (tileType == WorldTileType.WallB)
                    {
                        tileType = WorldTileType.Wall;
                    }
                }

                // world edges are always pillars
                if (_numCols > 10 && _numRows > 10)
                {
                    if (col == 0 || col == _numCols - 1)
                    {
                        tileType = WorldTileType.Pillar;
                    }
                    else if (row == 0 || row == _numRows - 1)
                    {
                        tileType = WorldTileType.Pillar;
                    }
                }

                WorldTile tile = CreateTile(col, row, tileType);
                _tiles[col, row] = tile;

                // remember where we put the rooms so we can easily choose a random room to start our generation
                if (tile.TileType == WorldTileType.Room)
                {
                    _listRooms.Add(tile);
                }
            }

            // frame limiting
            if (row % _generationRate == 0)
            {
                yield return(new WaitForEndOfFrame());
            }
        }

        //Debug.Log("connecting adjoined tiles...");

        yield return(new WaitForEndOfFrame());

        // connect adjoined tiles
        for (int row = 0; row < _numRows; row++)
        {
            for (int col = 0; col < _numCols; col++)
            {
                WorldTileConfig tileConfig = _tileSeed.GetTileConfig(col, row);
                if (tileConfig.ParentX != 0 || tileConfig.ParentY != 0)
                {
//					Debug.Log(" tile " + col + "x" + row + " is a child of offset (" + tileConfig.ParentX + "," + tileConfig.ParentY + ")");

                    WorldTile parentTile = GetTile(col + tileConfig.ParentX, row + tileConfig.ParentY);
                    if (parentTile != null)
                    {
                        WorldTile childTile = GetTile(col, row);

//						Debug.Log("  >> setting tile " + childTile + " as child of " + parentTile + " ==> (" + tileConfig.ParentX + "," + tileConfig.ParentY + ")");

                        childTile.SetParentTile(parentTile);
                    }
                }
            }

//			yield return new WaitForEndOfFrame();
        }
    }