public void DropPieces() { currentState = BoardState.Falling; piecesInProgress = new List <Piece> (); for (int x = 0; x < pieces.GetLength(0); x++) { int lowY = -1; int emptySpaces = 0; for (int y = 0; y < pieces.GetLength(1); y++) { var piece = GetPiece(x, y); if (piece == null) { pieces [x, y] = null; emptySpaces++; if (lowY == -1) { lowY = y; } } else { if (lowY >= 0 && lowY < y) { MovePiece(new Vector2Int(x, y), new Vector2Int(x, lowY), AnimationSettings.FallSpeed); pieces [x, lowY] = piece; pieces [x, y] = null; int l = 0; while (HasPiece(x, l)) { if (GetPiece(x, l) == null || GetPiece(x, l).state == PieceState.Destroyed) { lowY = l; break; } l++; } } } } Debug.LogWarning(emptySpaces); for (int y = Height; y < Height + emptySpaces; y++) { var piece = PiecePool.CreatePiece(); Debug.Log("Make piece " + piece.name); piece.transform.SetParent(transform); piece.transform.localPosition = GetPiecePosition(new Vector2Int(x, y)); piece.Init(Random.Range(0, ColorSettings.colorCount)); MovePiece(piece, new Vector2Int(x, y - emptySpaces), AnimationSettings.FallSpeed); pieces [x, y - emptySpaces] = piece; } } }
public override void GenerateBoard(LevelData data) { base.GenerateBoard(data); for (int x = 0; x < data.width; x++) { for (int y = 0; y < data.height; y++) { var piece = PiecePool.CreatePiece(); piece.transform.SetParent(transform); piece.transform.localPosition = GetPiecePosition(new Vector2Int(x, y)); if (levelData.definition != null) { piece.Init(levelData.colors [x, y]); } else { piece.Init(Random.Range(0, ColorSettings.colorCount)); } pieces [x, y] = piece; } } }