So I've been checking some games to get ideas for my own. Some designs I've reviewed rely on a few variables like:
- Current level
- Current exp
- Exp to next level
I aim for a simplistic design where there is only an exp variable.
Example:
Level 1
Current exp: 0
Exp to next level: 100
Level 2
Current exp: 100
Exp to next level: 200
Level 3
Current exp: 200
Exp to next level: 400
Level 4
Current exp: 400
Exp to next level: 800
Every level, the exp required for next level doubles.
That's okay. Since I use only an exp variable, I need two formulas:
- Formula to calculate the current level
- Formula to calculate the exp required for next level
My progress so far:
Level = floor((exp + 100)/100)
This works for 0 exp (level 1) because floor(0 + 100)/100 equals 1, with 50 exp works fine too:
50 + 100 = 150 150/100 1.5 flooring 1,5 gets us to 1
If we hit 100 exp, we should be now at level 2.
floor((100+100)/100) = 2
Let's see level three.
floor((100 + 200)/100) = 3
Since level 3 is at least 200 exp, this thing keeps working.
Level 4 begins with 400 exp.
Let's see what happens if we have 399 exp. 399 + 100 499/100 = 4.9 floor(4.9) 4
No way. 399 should still be level 3.
So let's take into account the doubling factor.
Level = floor((exp + 100)/100)/2
399 + 100 = 499... / 100 = 4.99 .. floored -> 4 / 2 = 2
Level 2? No way , it should be level 3
Another try:
Level = floor((exp/100))
floor(399/100) = 3 floor(400/100) = 4
But if we apply the formula to level 2(starting at 100, ending at 200 which would be level 3)
floor(100/100) = 1
I can't seem to achieve this on my own. Any suggestions?