Ejemplo n.º 1
0
    void OnMouseDown()
    {
        Level last = Levels.AllLevels[Levels.AllLevels.Count - 1];

        SaveManager.Beaten(last);
        SaveManager.Write();
    }
Ejemplo n.º 2
0
    IEnumerator FinishLevel()
    {
        Debug.Log("Level finished!");

        // Wait time between stars unless tapped to skip
        const bool playting = true;
        const bool playfail = false;

        // Which stars are unlocked
        bool scoreStar = false;
        bool timeStar  = false;

        Debug.Log("Updating next level");

        hasFinished = true;

        // Calculate scores
        Debug.Log("Calculating scores");

        score = new Save.LevelHighScore();

        if (!GameRecorder.playingBack)
        {
            score.Score = ScoreCalculator.finalScore;
            score.Speed = ScoreCalculator.finalSpeed;
            score.Time  = ScoreCalculator.finalTime;
        }
        else
        {
            score.Score = GameRecorder.current.score.score;
            score.Speed = GameRecorder.current.score.speed;
            score.Time  = GameRecorder.current.score.time;
        }

        // Save recording
        Debug.Log("Save recording!");

        if (!GameRecorder.playingBack)
        {
            savedRecording = true;
            GameRecorder.StopRecording();
            //Recording rec = GameRecorder.Save(true, false);

            // Upload score to online thing
            if (!GameRecorder.playingBack)
            {
                //HighScores.PostScore(LevelSelectGUI.currentLevel, rec);
            }
            // Disable buttons so user doesn't disrupt score uploading
            GUIController.DisableButtons();
        }

        // Check which stars have been earnt
        Debug.Log("Checking speed star!");

        scoreStar = SaveManager.HasSurpassedSpeed(score, LevelSelectGUI.currentLevel);
        timeStar  = SaveManager.HasSurpassedTime(score, LevelSelectGUI.currentLevel);

        // Check rewards
        int passedReward     = 500;
        int noPowerupsReward = 500;
        int scoreReward      = scoreStar ? 500 : 0;
        int timeReward       = timeStar ? 500 : 0;

        // Get picolinium counter and set target to current value so we can manually increment it
        var picoliniumCounter = GameObject.Find("Game End/Content/Picolinium/Value/Content/Text")?.GetComponent <PicoliniumCounter>();

        picoliniumCounter.Target = SaveManager.save?.picolinium ?? 0;

        if (SaveManager.save != null)
        {
            SaveManager.save.levelCompletions++;
            SaveManager.save.IncrementPicolinium(passedReward + noPowerupsReward + scoreReward + timeReward);
        }

        // Update save
        // Don't save if we are replaying a recording.
        if (!GameRecorder.playingBack)
        {
            if (LevelSelectGUI.currentLevel != null)
            {
                SaveManager.Beaten(LevelSelectGUI.currentLevel);
                SaveManager.UpdateScore(LevelSelectGUI.currentLevel);
                SaveManager.Write();
            }
        }

        // Let the camera pan back a bit
        tapped = false;
        yield return(WaitButAllowSkip(START_WAIT_TIME));

        // Show the gui
        // Do everything important before this because they can exit the level or reset after this
        GameObject.Find("Game End").BroadcastMessage("Reset");
        GameObject.Find("MainGUI").GetComponent <Animator>().Play("EndLevel");

        tapped = false;
        yield return(new WaitForSeconds(0.5f));

        string formattedTime = ReadableTime((int)(score.Time * 1000.0f));

        // Get reward text template
        var bonusTemplate = GameObject.Find("RewardText");

        SoundManager.Play("ting");
        picoliniumCounter.Target += passedReward;

        // Show level time
        var levelTime = GameObject.Find("LevelTime/Text").GetComponent <TextRevealer>();

        levelTime.Text    = $"{formattedTime}";
        levelTime.Run     = true;
        levelTime.Counter = 0.0f;

        TextFadeout newBonusText;

        if (!tapped)
        {
            newBonusText      = GameObject.Instantiate(bonusTemplate, bonusTemplate.transform.parent).GetComponent <TextFadeout>();
            newBonusText.Text = "Level complete!";
            newBonusText.Go   = true;
        }

        yield return(WaitButAllowSkip(WAIT_TIME));

        // Show powerups bonus
        if (noPowerupsReward > 0)
        {
            picoliniumCounter.Target += noPowerupsReward;

            if (!tapped)
            {
                newBonusText      = GameObject.Instantiate(bonusTemplate, bonusTemplate.transform.parent).GetComponent <TextFadeout>();
                newBonusText.Text = "No powerups";
                newBonusText.Go   = true;

                SoundManager.Play("ting");
            }

            yield return(WaitButAllowSkip(WAIT_TIME));
        }

        // Show time bonus
        if (timeReward > 0)
        {
            picoliniumCounter.Target += timeReward;

            if (!tapped)
            {
                SoundManager.Play("ting");

                newBonusText      = GameObject.Instantiate(bonusTemplate, bonusTemplate.transform.parent).GetComponent <TextFadeout>();
                newBonusText.Text = "Super fast time!";
                newBonusText.Go   = true;
            }

            yield return(WaitButAllowSkip(WAIT_TIME));
        }

        // Show speed bonus
        if (scoreReward > 0)
        {
            picoliniumCounter.Target += scoreReward;

            if (!tapped)
            {
                SoundManager.Play("ting");

                newBonusText      = GameObject.Instantiate(bonusTemplate, bonusTemplate.transform.parent).GetComponent <TextFadeout>();
                newBonusText.Text = "Super fast speed!";
                newBonusText.Go   = true;
            }

            yield return(WaitButAllowSkip(WAIT_TIME));
        }

        // End
        player.SendMessage("StopCounting");

        player.SendMessage("EndMining");

        //GameObject.Find("Game End/Content/Story/Text").GetComponent<TextRevealer>().Run = true;
        GameObject.Find("MainGUI").GetComponent <Animator>().Play("ExpandEndLevel");

        if (!uploading)
        {
            GUIController.EndLevel(true);
        }

        endingDone = true;
    }