Example #1
0
    public static bool GotSpeedStar(Level level)
    {
        // Get index of level
        Save.LevelHighScore highscore = save.GetHighScore(level.world, level.number);

        return(GotWinStar(level) && HasSurpassedSpeed(highscore, level));
    }
Example #2
0
    public static bool HasSurpassedTime(Save.LevelHighScore score, Level level)
    {
        if (level != null)
        {
            return(score.Time <= level.ranks.TimeThreshold);
        }

        return(false);
    }
Example #3
0
    public static bool HasSurpassedSpeed(Save.LevelHighScore score, Level level)
    {
        if (level != null)
        {
            return(score.Speed >= level.ranks.SpeedThreshold);
        }

        return(false);
    }
Example #4
0
    //public static int LevelToLevelID(Level level)
    //{
    // Find which level this is.
    //int levelID = 0;
    //for (levelID = 0; levelID < Levels.AllLevels.Count; ++levelID)
    //{
    //if (Levels.AllLevels[levelID].CompareTo(level) == 0)
    //break;
    //}
    //
    //return levelID;
    //}

    public static void UpdateScore(Level level)
    {
        // Find which level this is.
        //int levelID = LevelToLevelID(level);

        // Get the score.
        Save.LevelHighScore score = new Save.LevelHighScore();
        score.Score = ScoreCalculator.finalScore;
        score.Speed = ScoreCalculator.finalSpeed;
        score.Time  = ScoreCalculator.finalTime;

        StarsThisLevel = GetStars(score, level);

        // Get the old score from file so we can check which ones we surpassed and award stars accordingly
        Save.LevelHighScore oldScore = save.GetHighScore(level.world, level.number);

        bool ignoreOldScore = false;

        // if old score was null
        if (oldScore.Time == 0)
        {
            ignoreOldScore = true;
        }

        // Get a star for winning.
        score.Stars = 1;

        // Star for surpassing score
        if (oldScore.Score >= level.ranks.SpeedThreshold && !ignoreOldScore)
        {
            score.Stars++;
        }
        else if (score.Score >= level.ranks.SpeedThreshold)
        {
            score.Stars++;
        }

        // Star for surpassing time
        if (oldScore.Time <= level.ranks.TimeThreshold && !ignoreOldScore)
        {
            score.Stars++;
        }
        else if (score.Time <= level.ranks.TimeThreshold)
        {
            score.Stars++;
        }

        // Update the score.
        if (save != null)
        {
            save.UpdateHighScore(score, level.world, level.number);
        }
    }
Example #5
0
    public static int GetStars(Save.LevelHighScore score, Level level)
    {
        // Get a star for winning
        int stars = 1;

        // Get a star for surpassing score
        if (HasSurpassedSpeed(score, level))
        {
            stars++;
        }

        // Get a star for surpassing time
        if (HasSurpassedTime(score, level))
        {
            stars++;
        }

        return(stars);
    }
Example #6
0
    public static bool GotTimeStar(Level level)
    {
        Save.LevelHighScore highscore = save.GetHighScore(level.world, level.number);

        return(GotWinStar(level) && HasSurpassedTime(highscore, level));
    }
    IEnumerator FinishLevel()
    {
        Debug.Log("Level finished!");

        // If this is a tutorial level, skip to the real level so scores and stuff are right
        if (tutorialCam != null)
        {
            LevelSelectGUI.currentLevel = Levels.GetLevel(tutorialCam.level);
            Debug.Log("In tutorial: skipping to level " + LevelSelectGUI.currentLevel.name);
        }

        // 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();
            }
        }

        // 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);

        // Reset press tracker so player can choose to skip
        tapped = false;

        // Let the camera pan back a bit
        yield return new WaitForSeconds(tapped ? 0 : WAIT_TIME);

        // Show first star
        Debug.Log("Showing speed star!");

        GUIController.EnableImage("Star0Locked");

        // Let the player know what this star's for
        //yield return new WaitForSeconds(tapped ? 0 : waitTime);
        GUIController.ShowText("Won", "Won");

        // Award level beaten star
        yield return new WaitForSeconds(tapped ? 0 : WAIT_TIME);
        GUIController.EnableImage("Star0");

        if (!tapped && playting)
            SoundManager.Play("ting");

        // Show score star
        yield return new WaitForSeconds(tapped ? 0 : WAIT_TIME);
        GUIController.EnableImage("Star1Locked");

        // Tell the player their score
        //yield return new WaitForSeconds(tapped ? 0 : waitTime);
        // Show to one decimal place (".#")
        //f/loat normalisedSpeed = (100.0f * score.Speed) / LevelSelectGUI.currentLevel.ranks.SpeedThreshold;
        //GUIController.ShowText("Speed", "Energy: " + ((int)normalisedSpeed).ToString() + "%");

        // Updated in Update() but needs to be enabled here like this
        speedWaitStart = Time.time;
        GUIController.ShowText ("Speed", "");

        // Award score star if score threshold beaten
        yield return new WaitForSeconds(tapped ? 0 : WAIT_TIME);
        if (scoreStar)
            GUIController.EnableImage("Star1");

        player.SendMessage("StopCounting");

        if (!tapped)
        {
            if (scoreStar && playting)
                SoundManager.Play("ting");
            else if (scoreStar && playfail)
                SoundManager.Play("fail");
        }

        // Show time star
        yield return new WaitForSeconds(tapped ? 0 : WAIT_TIME);
        GUIController.EnableImage("Star2Locked");

        // Shown in Update() but needs to be enabled here like this
        timeWaitStart = Time.time;
        GUIController.ShowText("Time", "");

        // Award star if time threshold beaten
        yield return new WaitForSeconds(tapped ? 0 : WAIT_TIME);
        if (timeStar)
            GUIController.EnableImage("Star2");

        if (!tapped)
        {
            if (timeStar && playting)
                SoundManager.Play("ting");
            else if (!timeStar && playfail)
                SoundManager.Play("fail");
        }

        yield return new WaitForSeconds(tapped ? 0 : WAIT_TIME);

        ScoreCalculator.Speed = 0;
        player.SendMessage("EndMining");

        // Show overall
        if (!GameRecorder.playingBack)
        {
            Level thisLevel = Levels.GetLevel(Application.loadedLevelName);
            if (thisLevel != null && thisLevel.highscores)
            {
                // Activate highscores menu.
                AskName.ActivateMenu();
            }

            GUIController.ShowText("Overall", "Overall");

            if (SaveManager.GotWinStar(LevelSelectGUI.currentLevel))
                GUIController.EnableImage("OverallStar0");
            else
                GUIController.EnableImage("OverallStar0Locked");

            if (SaveManager.GotSpeedStar(LevelSelectGUI.currentLevel))
                GUIController.EnableImage("OverallStar1");
            else
                GUIController.EnableImage("OverallStar1Locked");

            if (SaveManager.GotTimeStar(LevelSelectGUI.currentLevel))
                GUIController.EnableImage("OverallStar2");
            else
                GUIController.EnableImage("OverallStar2Locked");
        }

        bool worldBeaten = true;
        foreach (Level level in Levels.AllLevels)
        {
            if (level.world == LevelSelectGUI.currentLevel.world)
            {
                if (!SaveManager.GotWinStar(level) ||
                    !SaveManager.GotSpeedStar(level) ||
                    !SaveManager.GotTimeStar(level))
                {
                    worldBeaten = false;
                }
            }
        }

        if (worldBeaten)
        {
            if (LevelSelectGUI.currentLevel.world == 1)
            {
                GameCenterSingleton.Instance.AddAchievementProgress("w_1_o", 100.0f);
            }
            if (LevelSelectGUI.currentLevel.world == 2)
            {
                GameCenterSingleton.Instance.AddAchievementProgress("w_2_o", 100.0f);
            }
            if (LevelSelectGUI.currentLevel.world == 3)
            {
                GameCenterSingleton.Instance.AddAchievementProgress("w_3_o", 100.0f);
            }
            if (LevelSelectGUI.currentLevel.world == 4)
            {
                GameCenterSingleton.Instance.AddAchievementProgress("w_4_o", 100.0f);
            }
            if (LevelSelectGUI.currentLevel.world == 5)
            {
                GameCenterSingleton.Instance.AddAchievementProgress("w_5_o", 100.0f);
            }
        }

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

        endingDone = true;
    }
    public static void UpdateScore(Level level)
    {
        // Find which level this is.
        int levelID = LevelToLevelID(level);

        // Get the score.
        Save.LevelHighScore score = new Save.LevelHighScore();
        score.Score = ScoreCalculator.finalScore;
        score.Speed = ScoreCalculator.finalSpeed;
        score.Time = ScoreCalculator.finalTime;

        StarsThisLevel = GetStars(score, level);

        // Get the old score from file so we can check which ones we surpassed and award stars accordingly
        Save.LevelHighScore oldScore = save.GetHighScore(levelID);

        bool ignoreOldScore = false;
        // if old score was null
        if (oldScore.Time == 0)
            ignoreOldScore = true;

        // Get a star for winning.
        score.Stars = 1;

        // Star for surpassing score
        if (oldScore.Score >= level.ranks.SpeedThreshold && !ignoreOldScore)
        {
            score.Stars++;
        }
        else if (score.Score >= level.ranks.SpeedThreshold)
        {
            score.Stars++;
        }

        // Star for surpassing time
        if (oldScore.Time <= level.ranks.TimeThreshold && !ignoreOldScore)
        {
            score.Stars++;
        }
        else if (score.Time <= level.ranks.TimeThreshold)
        {
            score.Stars++;
        }

        // Update the score.
        if (save != null)
            save.UpdateHighScore(score, levelID);
    }
Example #9
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;
    }