Ejemplo n.º 1
0
    IEnumerator ExplodeCluster(List <GridBubble> bubbleCluster)
    {
        if (bubbleCluster.Count == 1)
        {
            Debug.LogError("what");
            yield break;
        }

        //* Exploding the topmost bubble is more fun
        GridBubble topMostBubble = bubbleCluster[0];

        for (int i = 1; i < bubbleCluster.Count; i++)
        {
            if (bubbleCluster[i].Bubble.GetBubblePosition().z > topMostBubble.Bubble.GetBubblePosition().z)
            {
                topMostBubble = bubbleCluster[i];
            }
        }

        //* Gather cluster into the top mostbubble
        yield return(playLoop.StartCoroutine(TweenBubbleGathering(bubbleCluster, topMostBubble)));

        List <GridBubble> neighbours = GetAllActiveNeighbours(topMostBubble);

        yield return(playLoop.StartCoroutine(TweenBubbleGathering(neighbours, topMostBubble)));

        // ! add explosion anim

        Camera.main.DOShakePosition(0.3f, 0.03f, 20, 90, false);

        topMostBubble.ActivateBubble(false);

        propagationComplete.Invoke();
    }
Ejemplo n.º 2
0
    IEnumerator SpawnRowRoutine(OnRowSpawnResult onRowSpawnResult)
    {
        bool  isGameOver   = false;
        float oddRowOffset = isOddRow ? bubbleRadius : 0f;

        isOddRow = !isOddRow;

        ToplineBubbles.Clear();

        for (int i = 0; i < GRID_WIDTH; i++)
        {
            yield return(new WaitForSeconds(0.1f));

            GridBubble lastSlot = bubbleGrid.Dequeue();

            // todo change gmeover condition, it will not work for the player added bubbles
            if (lastSlot.IsActive)
            {
                //* Add a call to a dequeued Bubble, if it exists it could run some game over destruction anim
                isGameOver = true;
                Debug.Log("game over");
            }

            //* activate new slot
            float xPosition = horizontalStep * i + oddRowOffset;
            lastSlot.ActivateBubble(new Vector3(xPosition, 0f, verticalStep));
            lastSlot.Bubble.ResetBubbleScale();
            bubbleGrid.Enqueue(lastSlot);
            ToplineBubbles.Add(lastSlot);
        }

        // * dirtyyy
        if (!isGameOver)
        {
            foreach (var bubble in bubbleGrid)
            {
                bubble.OffsetBubble(-verticalStep);
            }
        }

        onRowSpawnResult(isGameOver);
    }
Ejemplo n.º 3
0
    IEnumerator CreateFirstRowsRoutine(Action onCompleted)
    {
        isOddRow = GRID_HEIGHT % 2 == 0 ? true : false;

        GenerateInactiveGrid();

        for (int j = 0; j < STARTING_ROWS; j++)
        {
            float oddRowOffset = isOddRow ? bubbleRadius : 0f;
            isOddRow = !isOddRow;

            for (int i = 0; i < GRID_WIDTH; i++)
            {
                yield return(new WaitForSeconds(0.1f));

                GridBubble newSlot   = bubbleGrid.Dequeue();
                float      xPosition = horizontalStep * i + oddRowOffset;
                newSlot.Bubble.ResetBubbleScale();
                newSlot.ActivateBubble(new Vector3(xPosition, 0f, verticalStep));
                bubbleGrid.Enqueue(newSlot);

                if (j == STARTING_ROWS - 1)
                {
                    ToplineBubbles.Clear();
                    ToplineBubbles.Add(newSlot);
                }
            }

            foreach (var bubble in bubbleGrid)
            {
                bubble.OffsetBubble(-verticalStep);
            }
        }

        onCompleted?.Invoke();
    }