コード例 #1
0
 private void InitializeCandyPools(int nbCandies)
 {
     redCandyPool    = new CandyPool(candyRed, numberOfPooledCandies, poolContainer);
     blueCandyPool   = new CandyPool(candyBlue, numberOfPooledCandies, poolContainer);
     orangeCandyPool = new CandyPool(candyOrange, numberOfPooledCandies, poolContainer);
     greenCandyPool  = new CandyPool(candyGreen, numberOfPooledCandies, poolContainer);
     yellowCandyPool = new CandyPool(candyYellow, numberOfPooledCandies, poolContainer);
 }
コード例 #2
0
    /// <summary>
    /// This static function returns a GridElement_Candy to its pool according to its color variable.
    /// </summary>
    /// <param name="candy"></param>
    public static void ReturnCandyToPool(GridElement_Candy candy)
    {
        CandyPool pool = null;

        switch (candy.color)
        {
        case GridElement_Candy.CandyColor.red:
            pool = S.redCandyPool;
            break;

        case GridElement_Candy.CandyColor.blue:
            pool = S.blueCandyPool;
            break;

        case GridElement_Candy.CandyColor.green:
            pool = S.greenCandyPool;
            break;

        case GridElement_Candy.CandyColor.yellow:
            pool = S.yellowCandyPool;
            break;

        case GridElement_Candy.CandyColor.orange:
            pool = S.orangeCandyPool;
            break;

        default:
            Debug.LogError("GridDisplayer.cs : The candy you are trying to return to its pool has an unrecognized color.", candy.gameObject);
            break;
        }

        if (pool != null)
        {
            pool.ReturnToPool(candy.gameObject);
        }
    }
コード例 #3
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);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 真正的消除了
        /// </summary>
        private void _Pop()
        {
            //计分
            if (IsNormalOrSpecial)
            {
                MyGrid.AddComboAmountOne();
                int addEnergy;
                if (0 <= Genre && Genre < GameData.CandyEnergyList.Length)
                {
                    addEnergy = GameData.CandyEnergyList[Genre] * MyGrid.CurrentComboMultiple;
                }
                else
                {
                    addEnergy = 1;
                }
                GameManager.Instance.PopEffectContainer.NormalPopEffect(CurIJ, Genre); //普通消除特效
                EnergyLightSpot.Create(CurIJ, addEnergy);                              //能量光点
                //if (MyGrid.CurrentComboMultiple > 1)
                //{
                //    GameManager.Instance.CellEffectContainer.CreateAddComboLabel(MyGrid.GetCellPosition(CurIJ),
                //                                                                 MyGrid.CurrentComboMultiple);
                //}
            }
            else if (MyType == CandyType.Item)
            {
                switch (Genre)
                {
                case 202:
                    GameData.MyHealth += 300;
                    break;

                case 203:
                    EnergyLightSpot.Create(CurIJ, 50);
                    break;

                case 204:
                    //TODO:钱袋
                    break;
                }
            }

            if (MyGrid[CurIJ].MyCandy == this)
            {
                MyGrid[CurIJ].MyCandy = null;
            }

            //if (MyType == CandyType.H)
            //{
            //    GameManager.Instance.PopEffectContainer.StripeHSpecialPopEffect(CurIJ, Genre);
            //}
            //else if (MyType == CandyType.V)
            //{
            //    GameManager.Instance.PopEffectContainer.StripeVSpecialPopEffect(CurIJ, Genre);
            //}
            //else if (MyType == CandyType.Bomb)
            //{
            //    if (FiredBombRange < 4)
            //    {
            //        GameManager.Instance.PopEffectContainer.Bomb3SpecialPopEffect(CurIJ, Genre);
            //    }
            //    else
            //    {
            //        GameManager.Instance.PopEffectContainer.Bomb5SpecialPopEffect(CurIJ, Genre);
            //    }
            //}

            //消除音效
            AudioManager.PlayRandomOneShot(0.2f, PopAudios);

            CandyPool.Enqueue(gameObject, 1f);
        }
コード例 #5
0
 void Awake()
 {
     Instance = this;
 }