Esempio n. 1
0
        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;
                }
            }
        }
Esempio n. 2
0
 public override void ClearBoard()
 {
     base.ClearBoard();
     for (int x = 0; x < pieces.GetLength(0); x++)
     {
         for (int y = 0; y < pieces.GetLength(1); y++)
         {
             PiecePool.DestroyPiece(pieces [x, y]);
         }
     }
     pieces = new Piece[0, 0];
 }
Esempio n. 3
0
    protected virtual IEnumerator DestroyCoroutine(System.Action <Piece> onComplete, float delay = 0)
    {
        if (delay > 0)
        {
            yield return(new WaitForSeconds(delay));
        }

        state = PieceState.Destroyed;
        transform.DOScale(Vector3.one * 0.5f, AnimationSettings.DestroyTime).SetEase(Ease.InBack);

        yield return(new WaitForSeconds(AnimationSettings.DestroyTime * destructionTimePercentage));

        onComplete.Invoke(this);

        yield return(new WaitForSeconds(AnimationSettings.DestroyTime * (1 - destructionTimePercentage)));

        PiecePool.DestroyPiece(this);
    }
Esempio n. 4
0
 /// <summary>
 /// Loads all pieces and dispatches them in pools
 /// </summary>
 private void LoadPiecesWithPools()
 {
     _manualPools = new Dictionary <int, PiecePool>();
     Piece[] objects = Resources.LoadAll <Piece>("Pieces");
     pieces = new List <Piece>();
     foreach (Piece obj in objects)
     {
         int       poolIndex = obj.poolIndex;
         PiecePool pool;
         if (!_manualPools.ContainsKey(poolIndex))
         {
             pool = new PiecePool();
             _manualPools.Add(poolIndex, pool);
         }
         else
         {
             _manualPools.TryGetValue(poolIndex, out pool);
         }
         pool.AddPiece(obj);
     }
 }
Esempio n. 5
0
        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;
                }
            }
        }