コード例 #1
0
        /// <summary>
        /// Меняет местами позиции объектов.
        /// </summary>
        public void SwapObjectPositions(GameBoardObject object1, GameBoardObject object2)
        {
            Debug.WriteLine($"Swapping {object1} and {object2}");
            // Меняем позиции
            Vector2Int object1Pos = object1.worldPos;
            Vector2Int object2Pos = object2.worldPos;

            object1.worldPos = object2Pos;
            object2.worldPos = object1Pos;
            // Запускаем анимации
            MoveAnimation moveAnimation1 = new MoveAnimation(object1, object1Pos, object2Pos, duration: 0.3, blocking: true);
            MoveAnimation moveAnimation2 = new MoveAnimation(object2, object2Pos, object1Pos, duration: 0.3, blocking: true);

            activeAnimations.Add(moveAnimation1);
            activeAnimations.Add(moveAnimation2);
        }
コード例 #2
0
        /// <summary>
        /// Активирует бонус Line.
        /// </summary>
        public void TriggerLineBonus(LineBonus lineBonus)
        {
            Debug.WriteLine("Creating destroyers");
            // Скорость разрушителей
            Vector2 destroyerDestination1;
            Vector2 destroyerDestination2;

            if (lineBonus.vertical)
            {
                destroyerDestination1 = new Vector2(lineBonus.worldPos.x, -1.0f);
                destroyerDestination2 = new Vector2(lineBonus.worldPos.x, 8.0f);
            }
            else
            {
                destroyerDestination1 = new Vector2(-1.0f, lineBonus.worldPos.y);
                destroyerDestination2 = new Vector2(8.0f, lineBonus.worldPos.y);
            }
            // Создание разрушителей
            Destroyer destroyer1 = new Destroyer(lineBonus.worldPos);
            Destroyer destroyer2 = new Destroyer(lineBonus.worldPos);

            destroyerList.Add(destroyer1);
            destroyerList.Add(destroyer2);
            // Запуск анимации
            MoveAnimation moveAnimation1 = new MoveAnimation(
                destroyer1,
                speed: 10.0,
                lineBonus.worldPos,
                destroyerDestination1,
                blocking: true,
                finishedCallback: _ => destroyerList.Remove(destroyer1)
                );
            MoveAnimation moveAnimation2 = new MoveAnimation(
                destroyer2,
                speed: 10.0,
                lineBonus.worldPos,
                destroyerDestination2,
                blocking: true,
                finishedCallback: _ => destroyerList.Remove(destroyer2)
                );

            activeAnimations.Add(moveAnimation1);
            activeAnimations.Add(moveAnimation2);
        }
コード例 #3
0
 /// <summary>
 /// Создает новые объекты сверху.
 /// </summary>
 public void CreateNewObjects()
 {
     Debug.WriteLine("Creating new objects");
     for (int x = 0; x < 8; x++)
     {
         // Сдвигаем висящие элементы
         int objectsUnder = 0;
         for (int y = 7; y >= 0; y--)
         {
             GameBoardObject gameBoardObject = GetObjectAtPosition(x, y);
             if (gameBoardObject != null)
             {
                 Vector2Int newPos = new Vector2Int(gameBoardObject.worldPos.x, 7 - objectsUnder);
                 if (gameBoardObject.worldPos != newPos)
                 {
                     MoveAnimation moveAnimation = new MoveAnimation(gameBoardObject, gameBoardObject.worldPos, newPos, duration: 0.3, blocking: true);
                     activeAnimations.Add(moveAnimation);
                     gameBoardObject.worldPos = newPos;
                 }
                 objectsUnder++;
             }
         }
         // Добавляем новые элементы
         int newElementCount = 8 - objectsUnder;
         for (int new_i = 0; new_i < newElementCount; new_i++)
         {
             // Позиция объекта и спрайта
             Vector2Int pos       = new Vector2Int(x, new_i);
             Vector2    spritePos = pos - new Vector2(0, newElementCount);
             // Создание объекта
             GameBoardObject randomObject = CreateRandomElement(pos, spritePos);
             objectList.Add(randomObject);
             // Запуск анимации
             MoveAnimation moveAnimation = new MoveAnimation(randomObject, spritePos, pos, duration: 0.3, blocking: true);
             activeAnimations.Add(moveAnimation);
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Изменяет фазу игры, если это необходимо.
        /// </summary>
        public void ChangeState()
        {
            // Если закончилось время
            if (timeRemaining < 0)
            {
                currentGamePhase = GamePhase.GameOver;
                return;
            }
            // Если есть блокирующие анимации, то состояние изменять нельзя
            if (activeAnimations.FindAll(animation => animation.blocking).Count > 0)
            {
                return;
            }
            // Смена элементов местами
            if (currentGamePhase == GamePhase.ElementSwap)
            {
                ComboList comboList = GetComboList();
                if (comboList.Count == 0)
                {
                    currentGamePhase = GamePhase.SwapBack;
                }
                else
                {
                    currentGamePhase = GamePhase.ComboDeletion;
                }
            }
            // Смена элементов обратно
            else if (currentGamePhase == GamePhase.SwapBack)
            {
                // Сохранение позиций объектов
                Vector2Int object1Pos = objectSwap1.worldPos;
                Vector2Int object2Pos = objectSwap2.worldPos;
                // Смена объектов местами
                objectSwap1.worldPos = object2Pos;
                objectSwap2.worldPos = object1Pos;
                // Запуск анимации
                MoveAnimation moveAnimation1 = new MoveAnimation(objectSwap1, object1Pos, object2Pos, duration: 0.3, blocking: true);
                MoveAnimation moveAnimation2 = new MoveAnimation(objectSwap2, object2Pos, object1Pos, duration: 0.3, blocking: true);
                activeAnimations.Add(moveAnimation1);
                activeAnimations.Add(moveAnimation2);

                ClearSelection();
                currentGamePhase = GamePhase.ComboDeletion;
            }
            // Удаление комбинаций
            else if (currentGamePhase == GamePhase.ComboDeletion)
            {
                ComboList comboList = GetComboList();
                if (comboList.Count == 0)
                {
                    currentGamePhase = GamePhase.Normal;
                }
                else
                {
                    DeleteCombos(comboList);
                    currentGamePhase = GamePhase.ElementSlide;
                }
            }
            // Создание новых элементов
            else if (currentGamePhase == GamePhase.ElementSlide)
            {
                CreateNewObjects();
                currentGamePhase = GamePhase.ComboDeletion;
            }
            // Работа бонусов
            else if (currentGamePhase == GamePhase.Bonus)
            {
                currentGamePhase = GamePhase.ComboDeletion;
            }
        }