Ejemplo n.º 1
0
    /// <summary>
    /// Coroutine that handles the play time of a given level
    /// Pro tip don't run your game using a coroutine because any errors will kill it
    /// </summary>
    IEnumerator FinalCountdown()
    {
        completionTime = 0;
        CanvasManager.CM.pointsManager.scoreUIText.transform.parent.gameObject.SetActive(false);
        countdownSlider.gameObject.SetActive(false);
        CanvasManager.CM.PreventAllPlayerInput = true;
        CanvasManager.CM.player.PreventAttacks = true;
        CanvasManager.CM.player.InCutscene     = true;

        if (!Application.isEditor && isGameLevel)
        {
            useCountdown = true;
        }
        if (useCountdown)
        {
            yield return(new WaitForSeconds(startCutsceneLength));
        }
        if (CountdownCompleted != null)
        {
            CountdownCompleted();
        }

        CanvasManager.CM.player.InCutscene     = false;
        CanvasManager.CM.PreventAllPlayerInput = false;
        CanvasManager.CM.player.PreventAttacks = false;
        GameSceneManager.allowedToPause        = true;

        if (CutsceneEnded is TimedEvent)
        {
            CutsceneEnded();
        }
        AllowedToGainPoints = true;
        if (isGameLevel)
        {
            CanvasManager.CM.pointsManager.scoreUIText.transform.parent.gameObject.SetActive(true);
        }

        //Set up timer UI variables
        sliderFill.color         = Color.white;
        countdownSlider.maxValue = maxSeconds;
        if (isGameLevel)
        {
            countdownSlider.gameObject.SetActive(true);
        }
        countdownStageCurrent = 1;
        countdownStagePrior   = 1;
        int quarter = maxSeconds / 4;

        //manage game
        while (!hasWon && secondsElapsed < maxSeconds)
        {
            AnimateTimerBasedOnGameProgress();

            secondsElapsed++;
            timerHandleOld  = timerHandleGoal;
            timerHandleGoal = maxSeconds - secondsElapsed;
            perSecondLerp   = 0;
            yield return(oneSecond);
        }

        if (timerSparks != null)
        {
            timerSparks.Stop();
        }

        GameSceneManager.allowedToPause = false;
        GameResolved();
        AllowedToGainPoints = false;
        CanvasManager.CM.player.PreventInput = true;
        CanvasManager.CM.movesetUI.transform.parent.gameObject.SetActive(false);
        CutsceneStarted();

        //if they player wins, the character stops possessing a body and runs away
        //if they lose, they fall over dead
        if (hasWon)
        {
            CanvasManager.CM.player.HandleBodyExit();
            CanvasManager.CM.player.InCutscene = true;
        }
        else
        {
            CanvasManager.CM.player.DiedInCutscene();
        }

        if (!GameSceneManager.GameOverScreenShowing)
        {
            GameSceneManager.GameOverScreenShowing = true;
        }

        //after stopping inputs, wait a second before showing the end screen for a stronger effect on the player
        yield return(oneSecond);

        CanvasManager.CM.deathScreen.HideScreen();

        //show game over screen
        gameOverScreen.gameObject.SetActive(true);
        if (hasWon)
        {
            gameOverScreen.AddHighScore(false, CanvasManager.CM.pointsManager.TotalPoints, secondsToMinutes(completionTime));
        }
        else
        {
            gameOverScreen.AddHighScore(true, CanvasManager.CM.pointsManager.TotalPoints, "");
        }
        CanvasManager.CM.inGameUIListener.ShowGameOverScreen();
    }