/// <summary> /// Restarts the level. /// </summary> public void RestartLevel() { // if the level finished to load if (m_LevelLoaded) { m_LevelLoaded = false; // Delete all the Items on the grid ItemManager.instance.ClearItems(); Vector3Int tileIndex = Vector3Int.zero; for (int i = 0; i < m_GridHorSize; i++) { for (int j = 0; j < m_GridVerSize; j++) { tileIndex.x = i; tileIndex.y = j; // Load a new item on each tile of the grid Item item = ItemManager.instance.LoadItem(m_HexMap.CellToWorld(tileIndex), tileIndex); m_PlayableGrid[i, j] = new PlayableHex(item); } } } m_LevelLoaded = true; }
/// <summary> /// Fills the empty hex tiles with items, on the column _indexY. /// </summary> /// <param name="_indexY">Index y.</param> private IEnumerator FillEmptyHexCo(int _indexY) { // for each row except the last one for (int i = 0; i < m_GridHorSize - 1; i++) { // if the tile is not filled and the tile above it is filled if (!m_PlayableGrid[i, _indexY].Filled && m_PlayableGrid[i + 1, _indexY].Filled) { // move the Item above on the tile below ItemManager.instance.MoveItem(m_PlayableGrid[i + 1, _indexY].Item, m_HexMap.CellToWorld(new Vector3Int(i, _indexY, 0))); m_PlayableGrid[i + 1, _indexY].Item.GridIndex = new Vector3Int(i, _indexY, 0); m_PlayableGrid[i, _indexY].Filled = true; m_PlayableGrid[i + 1, _indexY].Filled = false; // assign the item at its new place m_PlayableGrid[i, _indexY].Item = m_PlayableGrid[i + 1, _indexY].Item; } yield return(null); } int topIndex = m_GridHorSize - 1; // if tiles of column _indexY and of last row, is not filled if (!m_PlayableGrid[topIndex, _indexY].Filled) { // load a new random Item on the grid Item item = ItemManager.instance.LoadItem(m_HexMap.CellToWorld(new Vector3Int(topIndex, _indexY, 0)), new Vector3Int(topIndex, _indexY, 0)); m_PlayableGrid[topIndex, _indexY] = new PlayableHex(item); } yield return(null); }
/// <summary> /// Loads the level. /// </summary> private IEnumerator LoadLevelCo() { m_LevelLoaded = false; Vector3Int newTilePos = Vector3Int.zero; // First loop to place the tiles on by one for (int i = 0; i < m_GridHorSize; i++) { for (int j = 0; j < m_GridVerSize; j++) { yield return(new WaitForSeconds(Globals.TILE_INIT_DELAY)); newTilePos.x = i; newTilePos.y = j; m_HexMap.SetTile(newTilePos, m_BaseTile); } } // Second loop to make all items appear at the same time for (int i = 0; i < m_GridHorSize; i++) { for (int j = 0; j < m_GridVerSize; j++) { newTilePos.x = i; newTilePos.y = j; // load each item on the grid Item item = ItemManager.instance.LoadItem(m_HexMap.CellToWorld(newTilePos), newTilePos); m_PlayableGrid[i, j] = new PlayableHex(item); } } m_LevelLoaded = true; }