public void AddXP(int exp) { user.totalXP += exp; int tempLVL = Mathf.FloorToInt(expInc * Mathf.Sqrt(user.totalXP)); // LEVEL UP if (tempLVL > user.lvl) { // set new user level user.lvl = tempLVL; // unlock level specific rewards LevelRewards.UnlockLevelRewards(); // label manipulation lvlLabel.text = "[Level " + user.lvl + "]"; // show level up banner LevelUpBanner.instance.ShowBanner(); } float expNext = (inverseCalcFactor * (user.lvl + 1) * (user.lvl + 1)); float expLast = (inverseCalcFactor * user.lvl * user.lvl); float diff = expNext - user.totalXP; // progressbar manipulation lvlProgressBar.maxValue = expNext; lvlProgressBar.minValue = expLast; lvlProgressBar.value = (expNext - diff); }
// Update is called once per frame void Start() { controller = GameObject.Find("GameControllerObject").GetComponent <GameController>(); rewards = GameObject.Find("HUD").transform.Find("LevelRewards").GetComponent <LevelRewards>(); scoreText = GameObject.Find("HUD").transform.Find("Score").GetComponent <Text>(); stats = controller.GetPlayer().GetLevelStats(); Rotate(); }
public void FinishLevel() { player.GetLevelStats().SetStat(LevelRewards.ConditionType.Time, Time.timeSinceLevelLoad); LevelRewards levelRewards = GameObject.Find("HUD").transform.Find("LevelRewards").GetComponent <LevelRewards>(); rewardsPassable = levelRewards.Save(); ResetCar(); if (nextLevel > PlayerPrefs.GetInt("CurrentLevel")) { PlayerPrefs.SetInt("CurrentLevel", nextLevel); } SceneManager.LoadScene("LevelComplete", LoadSceneMode.Single); }
public LevelRewardsPassable(LevelRewards source) { rewardOneCondition = source.rewardOneCondition; rewardOneComparison = source.rewardOneComparison; rewardOneValue = source.rewardOneValue; rewardOnePrefab = source.rewardOnePrefab; rewardTwoCondition = source.rewardTwoCondition; rewardTwoComparison = source.rewardTwoComparison; rewardTwoValue = source.rewardTwoValue; rewardTwoPrefab = source.rewardTwoPrefab; rewardThreeCondition = source.rewardThreeCondition; rewardThreeComparison = source.rewardThreeComparison; rewardThreeValue = source.rewardThreeValue; rewardThreePrefab = source.rewardThreePrefab; }
// restores all savestate data and replaces instance vars accordingly public void LoadPrefs() { if (PlayerPrefs.HasKey("firststart")) { intro.SetActive(false); user = new User(PlayerPrefs.GetString("user_gender"), PlayerPrefs.GetInt("user_age"), PlayerPrefs.GetInt("user_height"), PlayerPrefs.GetInt("user_weight"), PlayerPrefs.GetInt("user_lvl"), PlayerPrefs.GetInt("user_totalXP")); AddXP(0); //add 0 XP to restore progressbar position lvlLabel.text = "[Level " + user.lvl + "]"; //deserialize json-string into workoutHistory-dict and restore it var dWorkoutHistory = JsonConvert.DeserializeObject <Dictionary <DateTime, List <WorkoutSession> > >(PlayerPrefs.GetString("workoutHistory")); workoutHistory = dWorkoutHistory; Color mainColor = PlayerPrefsX.GetColor("mainColor"); Color bgColor = PlayerPrefsX.GetColor("bgColor"); GameObject.FindGameObjectWithTag("Camera").GetComponent <Camera>().backgroundColor = bgColor; GameObject[] bgos = GameObject.FindGameObjectsWithTag("BGColor"); foreach (GameObject go in bgos) { go.GetComponent <UnityEngine.UI.Image>().color = bgColor; } GameObject[] gos = GameObject.FindGameObjectsWithTag("Header"); foreach (GameObject go in gos) { go.GetComponent <UnityEngine.UI.Image>().color = mainColor; } mainCol = mainColor; bgCol = bgColor; NotificationTimer.h = PlayerPrefs.GetInt("notification_h"); NotificationTimer.m = PlayerPrefs.GetInt("notification_m"); NotificationTimer.SetupLocalNotificationsOnReboot(NotificationTimer.h, NotificationTimer.m, 7); //unlock all currently unlocked rewards again LevelRewards.UnlockLevelRewards(); } else { intro.SetActive(true); } }
public static Dictionary <InventoryEnum, int> GetLevelRewards(LevelEnum levelEnum, bool completed, int lastAchievedStars, int achievedStars) { LevelRewards levelRewards = new LevelRewards(); switch (levelEnum) { case LevelEnum.TestingGround: levelRewards.participationReward.Add(InventoryEnum.Money, 3); // TODO rebalance // No rewards in test level break; case LevelEnum.IntroLevel1: levelRewards.participationReward.Add(InventoryEnum.Money, 3); // TODO rebalance levelRewards.participationReward.Add(InventoryEnum.PremiumMoney, 1); // TODO rebalance levelRewards.victoryReward.Add(InventoryEnum.Money, 7); // TODO rebalance levelRewards.oneStarReward.Add(InventoryEnum.Money, 10); // TODO rebalance levelRewards.twoStarReward.Add(InventoryEnum.Money, 10); // TODO rebalance levelRewards.threeStarReward.Add(InventoryEnum.Money, 20); // TODO rebalance break; case LevelEnum.IntroLevel2: // TODO break; case LevelEnum.IntroLevel3: // TODO break; default: Debug.LogError("LevelRewardInfo was not found."); break; } Dictionary <InventoryEnum, int> rewards = levelRewards.GetLevelRewards(lastAchievedStars, completed, achievedStars); return(rewards); }