Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class LevelSystem
- {
- int lvl;
- int exp;
- int expn;
- int totalExp;
- const int MAX_LEVEL = 100;
- public LevelSystem()
- {
- SetStartingExperience();
- Debug.Log("Level: " + lvl + " Experience: " + exp + " Experience Needed: " + expn + " Total Exp: " + totalExp);
- }
- public void SetStartingExperience()
- {
- lvl = 1;
- exp = 0;
- expn = GetExperienceNeeded(lvl);
- totalExp = exp;
- return;
- }
- public void AddExperience(int amount)
- {
- exp += amount;
- totalExp += amount;
- ExperienceCheck();
- }
- private void ExperienceCheck()
- {
- if(exp >= expn)
- {
- LevelUp();
- }
- else
- {
- return;
- }
- }
- private void LevelUp()
- {
- if (lvl == MAX_LEVEL)
- {
- return;
- }
- if (lvl != MAX_LEVEL && exp >= expn)
- {
- lvl += 1;
- exp -= expn;
- expn = GetExperienceNeeded(lvl);
- Debug.Log("Player gained a level! Player is now Level " + playerTamer.lvl);
- ExperienceCheck();
- }
- }
- private int GetExperienceNeeded(int level)
- {
- double baseXP = 500.0;
- double exponent = 2.0;
- level++;
- int newExp = (int)Math.Ceiling(baseXP * (Math.Pow((double)level, exponent)) - (baseXP * (double)level));
- return newExp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement