Esempio n. 1
0
 /// <summary>
 /// 由UpdateMoving统一调用的Update交换
 /// </summary>
 public void UpdateExchange()
 {
     if (State == CandyState.Exchange)
     {
         ExchangePhase += ExchangeSpeed * Time.deltaTime;
         if (ExchangeSuccessful && ExchangePhase >= 1) //成功的Exchange结束了
         {
             State = CandyState.Static;
             transform.localPosition = MyGrid.GetCellPosition(ExchangeToIJ);
             if (_isMainInExchange)
             {
                 MyGrid.AddFinishExchangeInfo(new Grid.ExchangeInfo(ExchangeToIJ, ExchangeFromIJ));
             }
             return;
         }
         if (!ExchangeSuccessful && ExchangePhase >= 2) //失败的Exchange结束了
         {
             State = CandyState.Static;
             transform.localPosition = MyGrid.GetCellPosition(ExchangeFromIJ);
             return;
         }
         var f = ExchangePhase > 1 ? 2 - ExchangePhase : ExchangePhase;
         transform.localPosition = MyGrid.GetCellFloatPosition(Mathf.Lerp(ExchangeFromIJ.i, ExchangeToIJ.i, f),
                                                               Mathf.Lerp(ExchangeFromIJ.j, ExchangeToIJ.j, f));
     }
 }
Esempio n. 2
0
 public void DragUp(BaseEventData baseEventData)
 {
     if (State == CandyState.Inactive)
     {
         return;
     }
     State = CandyState.NotDragging;
 }
Esempio n. 3
0
        /// <summary>
        /// 开始消除动作,立即标记为Popping状态
        /// </summary>
        /// <param name="delay"></param>
        public void Pop(float delay)
        {
            name  = "Candy " + CurIJ;
            State = CandyState.Popping;

            PopExtraDelay = delay;
            Invoke("_Pop", delay + 0.1f);

            CandyRenderer.Pop();
        }
Esempio n. 4
0
        /// <summary>
        /// 转换成交换状态。如果成功,还需要设置CurIJ,和Grid[IJ]含有的糖果
        /// </summary>
        /// <param name="fromCell">此时必须和CurIJ相同才对</param>
        /// <param name="toCell">马上就要将CurIJ设置成与这相同</param>
        /// <param name="isMain">是玩家操作的那个,会播放跃起放大动画</param>
        /// <param name="successful"></param>
        public void TransitionToExchange(IntVector2 fromCell, IntVector2 toCell, bool isMain, bool successful)
        {
            if (State != CandyState.Static)
            {
                Debug.LogError("怎么可能从非Static状态变为Exchange状态呢,务必检查");
            }
            State = CandyState.Exchange;

            _isMainInExchange  = isMain;
            ExchangeFromIJ     = fromCell;
            ExchangeToIJ       = toCell;
            ExchangeSuccessful = successful;
            ExchangePhase      = 0;

            if (isMain)
            {
                CandyRenderer.Exchange();
            }
        }
Esempio n. 5
0
 public void RestoreToActive() => this.State = CandyState.NotDragging;
Esempio n. 6
0
 public void InactiveState() => this.State   = CandyState.Inactive;
Esempio n. 7
0
        /// <summary>
        /// 由UpdateMoving统一调用的Update下落
        /// </summary>
        public void UpdateFalling()
        {
            if (State == CandyState.Falling) //在下落状态
            {
                FallingSpeed            += Acceleration * Time.deltaTime * (IsCrossColumn ? 0.5f : 1);
                transform.localPosition +=
                    new Vector3(IsCrossColumn ? (CurIJ.j - FromIJ.j) * Grid.CellSize.x : 0,
                                -(CurIJ.i - FromIJ.i) * Grid.CellSize.y)
                    * FallingSpeed * Time.deltaTime;

                CandyRenderer.HasSupport = false;
            }

            if ((State == CandyState.Falling && transform.localPosition.y < MyGrid.GetCellPosition(CurIJ).y) ||
                State == CandyState.Static)
            {
                //检测是否需要下落
                int fallingType      = 2; //1:正常下落 2:停止 3:石头漏出
                var nextCell         = IntVector2.zero;
                var isReachTheLowest = false;
                if (MyGrid[CurIJ].MyState == Cell.State.Normal) //所在格子是Normal才可以下落,否则肯定Lock住
                {
                    if (CurIJ.i < Grid.Height - 1)              //不在网格底部
                    {
                        //检测下方
                        for (int index = 0; index < CheckGoOnFallingList.Length; index++)
                        {
                            var fallingDir = CheckGoOnFallingList[index];

                            nextCell = CurIJ + fallingDir;

                            if (index == 0) //↓
                            {
                                if (!MyGrid.IsIJInGrid(nextCell))
                                {
                                    continue;                               //目标格子超出范围就放弃这个方向
                                }
                                while (true)
                                {
                                    if (MyGrid[nextCell].MyState != Cell.State.Null)
                                    {
                                        break;                                              //找到下方非Null格子中最靠上的
                                    }
                                    nextCell.i++;
                                    if (!MyGrid.IsIJInGrid(nextCell)) //如果已经超出网格范围,则说明下面全是Null,即已经在列的底部了
                                    {
                                        isReachTheLowest = true;
                                        break;
                                    }
                                }
                                if (isReachTheLowest)
                                {
                                    continue;                   //在列的底部肯定不能下落,不过可以看看是不是可以侧滑
                                }
                                //nextCell是CurIJ的下方非Null格子中最靠上的
                                if (!MyGrid[nextCell].CanHoldCandy || MyGrid[nextCell].MyCandy != null) //如果目标格不能持有糖果就放弃
                                {
                                    continue;
                                }
                                fallingType = 1; //确定下落方向为↓
                                break;           //不再检测其他方向
                            }
                            else //↙、↘
                            {
                                if (!MyGrid.IsIJInGrid(nextCell))
                                {
                                    continue;                                                           //目标格子超出范围就放弃这个方向
                                }
                                if (!MyGrid[nextCell].CanHoldCandy || MyGrid[nextCell].MyCandy != null) //如果目标格不能持有糖果就放弃
                                {
                                    continue;
                                }
                                //可以继续向dir下落
                                var theCellAboveNextCell = nextCell;
                                theCellAboveNextCell.i--;
                                do //验证目标格子上方是否有可以落下来的
                                {
                                    if (!MyGrid.IsIJInGrid(theCellAboveNextCell))
                                    {
                                        break;                                           //目标格子超出网格范围
                                    }
                                    if (MyGrid[theCellAboveNextCell].MyState == Cell.State.Brick ||
                                        MyGrid[theCellAboveNextCell].MyState == Cell.State.Lock)
                                    //如果那个空格的正上方是不可穿透的,就可以落进去。唯一确定能下落的出口!
                                    {
                                        fallingType = 1;
                                        break;
                                    }
                                    if (MyGrid[theCellAboveNextCell].MyState == Cell.State.Normal &&
                                        MyGrid[theCellAboveNextCell].MyCandy) //这个Candy会落到这个格子里的,所以不需要我侧滑
                                    {
                                        break;
                                    }
                                    //剩余的情况是Normal && 没有Candy
                                    theCellAboveNextCell.i--;
                                } while (theCellAboveNextCell.i >= 0);
                                if (fallingType == 1)
                                {
                                    break;                   //已经确定朝哪个方向下落了(↙、↓、↘),就跳出循环
                                }
                            }
                        }
                    }
                    else
                    {
                        isReachTheLowest = true;
                    }
                    if (fallingType == 2 && isReachTheLowest && MyType == CandyType.Stone)//石头
                    {
                        fallingType = 3;
                    }
                }

                if (fallingType == 1) //还能继续下滑
                {
                    if (State == CandyState.Falling)
                    {
                        if (!IsCrossColumn && nextCell.j != CurIJ.j)
                        {
                            FallingSpeed *= 0.707f;                                          //从向下变成斜向滑动时速度损耗
                        }
                        //Grid的逻辑层,释放旧的Cell,占领自己的Cell
                        if (MyGrid.IsIJInGrid(CurIJ))
                        {
                            MyGrid[CurIJ].MyCandy = null;
                        }
                        FromIJ = CurIJ;
                        CurIJ  = nextCell;
                        MyGrid[CurIJ].MyCandy = this;
                    }
                    else if (State == CandyState.Static)
                    {
                        State = CandyState.Falling;

                        //Grid的逻辑层,占领自己的Cell
                        FromIJ = CurIJ;
                        CurIJ  = nextCell;
                        MyGrid[CurIJ].MyCandy  = this;
                        MyGrid[FromIJ].MyCandy = null;
                    }
                }
                else if (fallingType == 2) //该停止了
                {
                    if (State == CandyState.Falling)
                    {
                        State = CandyState.Static;
                        transform.localPosition = MyGrid.GetCellPosition(CurIJ);
                        CushionAnimation.Play(); //缓冲,如果跳帧就用CrossFade
                        AudioManager.PlayOneShot(CushionAudio, Mathf.Clamp01((FallingSpeed - 5) / 25));
                        FallingSpeed             = 0;
                        CandyRenderer.HasSupport = true;
                    }
                    else if (State == CandyState.Static)
                    {
                    }
                }
                else if (fallingType == 3) //石头坠落
                {
                    // 漏出三消区
                    if (MyGrid[CurIJ].MyCandy == this)
                    {
                        MyGrid[CurIJ].MyCandy = null;
                    }
                    _isFallingOut = true;
                    CandyPool.Enqueue(gameObject, 1f);
                }
            }
        }