//returns number of lines (0 to 4) public int UpdateGrid( bool _absorbTetrimino = false) { List<int> linesYIndex = new List<int>(); //will store lines to remove List<Vector2Int> previousTetriminoCells = m_currentTetrimino.GetPreviousCellsPositions(); List<Vector2Int> newTetriminoCells = m_currentTetrimino.GetCurrentCellsPositions(); //clear old ones foreach(Vector2Int _pos in previousTetriminoCells) { if(PositionIsInsideGrid(_pos)) { m_gridTab[_pos.x, _pos.y].SetCellType(Cell.eCellType.EMPTY_CELL); m_gridTab[_pos.x, _pos.y].SetCellTetriminoType(Tetrimino.eTetriminoType.BLANK); } } //set new ones foreach(Vector2Int _pos in newTetriminoCells) { if(PositionIsInsideGrid(_pos)) { m_gridTab[_pos.x, _pos.y].SetCellType(_absorbTetrimino ? Cell.eCellType.BUSY_CELL : Cell.eCellType.TETRIMINO_CELL); m_gridTab[_pos.x, _pos.y].SetCellTetriminoType(m_currentTetrimino.GetTetriminoType()); //check lines (maybe redundant but doesn't cost much...) if(_absorbTetrimino) { if(IsMakingALine(_pos.y)) { if(!linesYIndex.Contains(_pos.y)) linesYIndex.Add(_pos.y); } } } } //find lower line to remove int lowerLineYtoRemove = m_gridSizeY; foreach (int lineIndex in linesYIndex) { if (lineIndex < lowerLineYtoRemove) lowerLineYtoRemove = lineIndex; } //then remove X time the same line for(int i = 0; i < linesYIndex.Count; i++) { RemoveLine(lowerLineYtoRemove); } RefreshRendering(); return linesYIndex.Count; }