Esempio n. 1
0
    void Update()
    {
        if (State == BlockState.BREAKING || State == BlockState.COLLECTING || State == BlockState.SWAPPING)
        {
            return;
        }

        if (MyTile != null && Fallable)
        {
            if (transform.position.y > MyTile.transform.position.y)
            {
                State = BlockState.FALLING;
            }

            // board object is settled squarely on its tile
            if (State == BlockState.SETTLED)
            {
                // if tile below becomes unoccupied, start falling again!
                Tile tileBelow = getTileAdjacent(0, 1);
                if (tileBelow != null && !tileBelow.IsOccupied(TileLayer))
                {
                    State = BlockState.FALLING;
                }
            }
            // the board object is falling vertically down
            else if (State == BlockState.FALLING)
            {
                // if the board object has fallen further than the targeted tile
                if (transform.position.y <= MyTile.transform.position.y)
                {
                    Tile targetTile = getTileAdjacent(0, 1);
                    if (targetTile == null || (targetTile != null && targetTile.IsOccupied(TileLayer)))
                    {
                        _velocity          = Vector3.zero;
                        transform.position = MyTile.transform.position;
                        State = BlockState.SETTLED;

                        if (!isBlockAbove())
                        {
                            if (!MyBoard.BreakMatchesInColumn(X))
                            {
                                MyBoard.ResetComboMultiplierForColumn(1, this);
                            }
                        }
                    }
                    // if not blocked then move to it
                    else if (targetTile != null)
                    {
                        MyTile.RemoveBoardObject(TileLayer);
                        targetTile.AddBoardObject(this, false);
                        advanceFallingObject();
                    }
                }
                else
                {
                    advanceFallingObject();
                }
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Adds the board object.
    /// </summary>
    /// <param name="boardObject">Board object.</param>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    public void AddBoardObject(Block boardObject, int x, int y, bool centerPos = true)
    {
        Tile t = GetTile(x, y);

        if (t != null)
        {
            t.AddBoardObject(boardObject, centerPos);
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Swap the specified t1 and t2.
    /// </summary>
    /// <param name="t1">T1.</param>
    /// <param name="t2">T2.</param>
    public void Swap(Tile t1, Tile t2)
    {
        if (t1 != null && t2 != null && !_swapOnCooldown)
        {
            Block b1 = t1.GetBoardObect(3);
            Block b2 = t2.GetBoardObect(3);

            _swapOnCooldown = true;
            bool swapB1 = false;
            bool swapB2 = false;

            if (b1 != null)
            {
                if ((b2 == null || b2.CanSwap()) && b1.CanSwap())
                {
                    swapB1 = true;
                }
            }

            if (b2 != null)
            {
                if (b1 == null || b1.CanSwap() && b2.CanSwap())
                {
                    swapB2 = true;
                }
            }

            if (swapB1 || swapB2)
            {
                if (swapB1 && swapB2)
                {
                    t1.AddBoardObject(b2, false);
                    t2.AddBoardObject(b1, false);
                    b1.Swap(t2);
                    b2.Swap(t1);
                }
                else if (swapB1 && !swapB2)
                {
                    t1.RemoveBoardObject(b1.TileLayer);
                    t2.AddBoardObject(b1, false);
                    b1.Swap(t2);
                }
                else if (swapB2 && !swapB1)
                {
                    t2.RemoveBoardObject(b2.TileLayer);
                    t1.AddBoardObject(b2, false);
                    b2.Swap(t1);
                }
                GameEventManager.TriggerEvent(GameEventType.MOVE);
            }

            LeanTween.delayedCall(0.1f, () =>
            {
                if (swapB1 || swapB2)
                {
                    if (swapB1 && swapB2)
                    {
                        b1.State = BlockState.SETTLED;
                        b2.State = BlockState.SETTLED;

                        BreakMatchesInColumn(b1.X, true);
                        BreakMatchesInColumn(b2.X, true);
                    }
                    else if (swapB1 && !swapB2)
                    {
                        b1.State           = BlockState.FALLING;
                        b1.ComboMultiplier = 1;
                    }
                    else if (swapB2 && !swapB1)
                    {
                        b2.State           = BlockState.FALLING;
                        b2.ComboMultiplier = 1;
                    }
                }

                _swapOnCooldown = false;
            });
        }
    }