Example #1
0
    private IEnumerator StartReverseCo()
    {
        yield return(new WaitUntil(() => BallSlotsByDistance.All(bs =>
                                                                 isDestroyingMatchingBalls == false &&
                                                                 (!bs.ball ||
                                                                  bs.ball.state != BallState.Landing &&
                                                                  bs.ball.state != BallState.SwitchingSlots)
                                                                 )
                                   ));

        isReverse = true;

        foreach (BallSlot ballSlot in ballSlots)
        {
            ballSlot.speedMultiplier = -1;
        }

        yield return(new WaitForSeconds(gameProperties.reverseDuration));

        foreach (BallSlot ballSlot in ballSlots)
        {
            ballSlot.speedMultiplier = 1;
        }

        isReverse = false;
    }
Example #2
0
    private IEnumerator DestroyMatchingBallsCo(BallSlot landedBallSlot)
    {
        isDestroyingMatchingBalls = true;

        List <BallSlot> ballsToDestroySlots;
        BallSlot        collidedBallSlot = landedBallSlot;

        do
        {
            yield return(new WaitUntil(() => BallSlotsByDistance.All(bs =>
                                                                     !bs.ball || bs.ball.state != BallState.Landing && bs.ball.state != BallState.SwitchingSlots)));

            ballsToDestroySlots = GetSimilarBalls(collidedBallSlot);

            if (ballsToDestroySlots.Count < 3)
            {
                break;
            }

            AddBallsIfThereIsBomb(ballsToDestroySlots);
            if (ballsToDestroySlots.FindIndex(bs => bs.ball.type == BallType.Reverse) != -1)
            {
                StartCoroutine(StartReverseCo());
            }
            if (ballsToDestroySlots.FindIndex(bs => bs.ball.type == BallType.TimeSlow) != -1)
            {
                StartCoroutine(TimeSlowCo());
            }

            foreach (BallSlot ballsToDestroySlot in ballsToDestroySlots)
            {
                ballsToDestroySlot.ball.StartDestroying();
                ballsToDestroySlot.AssignBall(null);
            }

            collidedBallSlot = ballsToDestroySlots[0];

            yield return(new WaitForSeconds(0.5f));

            MoveSeparatedBallsBack();
        } while (ballsToDestroySlots.Count >= 3 && collidedBallSlot);

        yield return(new WaitUntil(() => BallSlotsByDistance.All(bs =>
                                                                 !bs.ball || bs.ball.state != BallState.SwitchingSlots)));

        isDestroyingMatchingBalls = false;
    }