private void Awake() { instance = this; CheatsForDebugging(); #if UNITY_ANDROID && !UNITY_EDITOR if (Application.isEditor) { Handheld.Vibrate(); // Cheat to add vibration permission. } // Override default editor API level on actual Android device. AndroidJavaClass androidVersion = new AndroidJavaClass("android.os.Build$VERSION"); apiLevel = androidVersion.GetStatic <int>("SDK_INT"); #endif raycastPlane = new Plane(Vector3.up, waterHeight); // Raycastable plane at water level. startingCamPos = camTrans.position; // Cannot go behind starting cam Z. initFrogPos = frog.position; targetCamPos = startingCamPos; frogShadowScale = frogShadow.localScale; defaultFrogTilt = frogMeshTrans.localEulerAngles; inTransitionOrBusy = false; musicSource.ignoreListenerPause = true; // Continue playing in pause menu. asleepAchv = false; tileController.Initialize(); curGameStats = new GameSessionStats(); ResetVariablesAndGameState(); }
private Dictionary <string, int> GetBreakdownAndAwardPoints(GameSessionStats stats) { Dictionary <string, int> result = new Dictionary <string, int>(); int awardSum = 0; // Linear award for bugs eaten. if (stats.bugsEaten > 0) { result.Add("BUGS EATEN", stats.bugsEaten); awardSum += stats.bugsEaten; } // Bonus points for rare bugs. if (stats.firefliesEaten > 0) { result.Add("FIREFLIES EATEN", stats.firefliesEaten); awardSum += stats.firefliesEaten; } // Difficulty/survival multiplier. if (stats.highestDifficulty >= 3) { // Bonus (scales with bugs eaten) starts with 5% at difficulty level 3, and increases by 2% every 2 levels. float multiplier = 0.05f + ((stats.highestDifficulty - 3) / 2) * 0.02f; int bugBonus = Mathf.CeilToInt(stats.bugsEaten * multiplier); int standardBonus = (stats.highestDifficulty - 2); int bonus = Mathf.Max(bugBonus, standardBonus); result.Add("SURVIVAL BONUS", bonus); awardSum += bonus; } // Leap streak bonuses. if (stats.highestLeapStreak >= 30) { result.Add("FROGTASTIC STREAK", 45); awardSum += 45; } else if (stats.highestLeapStreak >= 20) { result.Add("INSANE STREAK", 30); awardSum += 30; } else if (stats.highestLeapStreak >= 15) { result.Add("AMAZING STREAK", 20); awardSum += 20; } else if (stats.highestLeapStreak >= 10) { result.Add("GREAT STREAK", 10); awardSum += 10; } // Sum up breakdown. shop.AwardFrogPoints(awardSum); return(result); }
public void ShowScoreScreen(GameSessionStats stats, bool drowned) { if (GameController.inTransitionOrBusy) { return; } scoreScreenRoutine = Timing.RunCoroutine(ScoreScreenRoutine(stats, drowned)); }
private IEnumerator <float> ScoreScreenRoutine(GameSessionStats gameStats, bool drowned) { GameController.inTransitionOrBusy = true; inMenu = true; pauseScreen.SetActive(false); scoreScreen.SetActive(true); ToggleGameHUD(false); scoreScreenBreakdown.alpha = 0f; scoreScreenTitle.text = (drowned) ? "YOU DROWNED" : "YOU GAVE UP"; int displayedFrogPoints = shop.currentFrogPoints; scoreScreenFrogPoints.text = displayedFrogPoints.ToString(); int highScore = PlayerPrefs.GetInt("HighScore", 0); int recordLeapStreak = PlayerPrefs.GetInt("RecordLeapStreak", 0); int recordLeapScore = PlayerPrefs.GetInt("RecordLeapScore", 0); int recordDifficulty = PlayerPrefs.GetInt("RecordDifficultyReached", 0); int recordNearMissStreak = PlayerPrefs.GetInt("RecordNearMissStreak", 0); int totalBugsEaten = PlayerPrefs.GetInt("TotalBugsEaten", 0); int totalFirefliesEaten = PlayerPrefs.GetInt("FirefliesEaten", 0); string highScoreColor = "21CE52"; // Set highscores. if (gameStats.finalScore > highScore) { highScore = gameStats.finalScore; PlayerPrefs.SetInt("HighScore", highScore); highScoreColor = "F2C637"; // Glow orange when achieved a new highscore. } if (gameStats.highestNearMissStreak > recordNearMissStreak) { recordNearMissStreak = gameStats.highestNearMissStreak; PlayerPrefs.SetInt("RecordNearMissStreak", recordNearMissStreak); } totalBugsEaten += gameStats.bugsEaten; PlayerPrefs.SetInt("TotalBugsEaten", totalBugsEaten); totalFirefliesEaten += gameStats.firefliesEaten; PlayerPrefs.SetInt("FirefliesEaten", totalFirefliesEaten); string stats = "Score: [21CE52]" + gameStats.finalScore + "[-]"; stats += "\nHigh Score: [" + highScoreColor + "]" + highScore + "[-]"; stats += "\nHighest Leap Streak: [21CE52]" + gameStats.highestLeapStreak + "[-]"; stats += "\nHighest Leap Score: [21CE52]" + gameStats.highestLeapScore + "[-]"; scoreScreenStats.text = stats; // Post values to leaderboard. game.gpgs.SubmitScoreToLeaderboard(GPGSIds.leaderboard_high_scores, gameStats.finalScore); game.gpgs.SubmitScoreToLeaderboard(GPGSIds.leaderboard_leap_streak, gameStats.highestLeapStreak); game.gpgs.SubmitScoreToLeaderboard(GPGSIds.leaderboard_leap_score, gameStats.highestLeapScore); game.gpgs.SubmitScoreToLeaderboard(GPGSIds.leaderboard_highest_difficulty, gameStats.highestDifficulty); // Award achievements and skins. achieve.UpdateProgressAll(true); // Awards points and returns score breakdown as a dictionary. Dictionary <string, int> breakdown = GetBreakdownAndAwardPoints(gameStats); float animTime = 0f; while (animTime < 1f) { animTime += Time.unscaledDeltaTime * scoreScreenAnimSpeed; float x = scoreScreenAnimCurve.Evaluate(animTime); scoreScreenTransform.localPosition = defaultScoreScreenPos + new Vector3(x, 0f, 0f); yield return(0f); } GameController.inTransitionOrBusy = false; // Score breakdown animation (can be skipped) int curBreakdownIndex = 0; foreach (KeyValuePair <string, int> pair in breakdown) { scoreScreenBreakdown.text = pair.Value + " - " + pair.Key; animTime = 0f; const float TRANSLATE_DIST = 8f; Vector3 pos = scoreScreenBreakdown.cachedTrans.localPosition; pos.y = -TRANSLATE_DIST; // Fade in, translate bottom -> middle. while (animTime < 1f) { animTime = Mathf.Min(animTime + (Time.unscaledDeltaTime * 4f), 1f); pos.y = (1f - animTime) * -TRANSLATE_DIST; scoreScreenBreakdown.cachedTrans.localPosition = pos; scoreScreenBreakdown.alpha = animTime; yield return(0f); } // Wait 0.5 seconds. pos.y = 0f; scoreScreenBreakdown.cachedTrans.localPosition = pos; scoreScreenBreakdown.alpha = 1f; animTime = 1f; yield return(Timing.WaitForSeconds(0.5f)); // Fade out, translate middle -> top while (animTime < 2f) { animTime = Mathf.Min(animTime + (Time.unscaledDeltaTime * 4f), 2f); pos.y = (animTime - 1f) * TRANSLATE_DIST; scoreScreenBreakdown.cachedTrans.localPosition = pos; scoreScreenBreakdown.alpha = 2f - animTime; yield return(0f); } // Animate total frog points. displayedFrogPoints += pair.Value; scoreScreenFrogPoints.text = displayedFrogPoints.ToString(); // Delay for next score breakdown if there is another one after this. if (curBreakdownIndex < breakdown.Count - 1) { yield return(Timing.WaitForSeconds(0.25f)); } curBreakdownIndex++; } }