so I was wondering what type of function i would use to set a steady increase for a experience / level up system
i did 8 * 1.25 in a program 100 times to get an idea of how it would play out if implemented and its alright but is there a better way to do it?
like this
level = exp/next_level
level 1 = 0/8
level 2 = 0/10
level 3 = 0/12
to display this i wrote this
i brought it down to 87 times because past that the integers become messed up and i dont know why.
level 89 (loop #88) = -2147483648
why does it come out with a -
#include <iostream>
usingnamespace std;
int main()
{
int A = 8;
int B = 0;
int C = 2;
while(B != 87)
{
A = A * 1.25;
B = B + 1;
cout << C << " = " << A << endl << endl;
C = C + 1;
}
system("PAUSE");
return 0;
}
If you've ever played Pokemon, you know that the leveling of Pokemon seems fair and balanced. You could do the same thing that the Pokemon games do for setting the next-level-exp-cap.
Actually, the Pokemon games have different kinds of Pokemon groups, which have different equations to set that level cap - which means not all Pokemon level the same. The point is, that you could use the same equation that the most common group uses, which is a simple cube of the level.
ExpRequiredForNextLevel = pow(CurrentLevel, 3)
level 89 (loop #88) = -2147483648
why does it come out with a -
The reason is because you're using signed integers to represent these values. Signed integers can only represent values between –2147483648 and 2147483647 (inclusive), so they'll "wrap around" if the value cannot be represented (either because it is too large, or too low). If you need to represent larger numbers, I would recommend using unsigned variables possibly in combination with 64 bit integer types.
Really, do it however you like. I generally prefer an exponential growth, simply because it means that it forces you to train at around your level (higher level monsters should be too difficult, and lower level monsters will give you increasingly negligible experience for your efforts). However, if you prefer a steady increase in experience, you could use something like a linear or quadratic growth, or something inbetween. Some examples of experience growth I've used before include:
1 2 3 4 5
unsignedlong exp; // big number for experience required
exp = pow(2.718, currLvl); // basic exponential growth
exp = currLvl * 10; // linear growth
exp = pow(currLvl, 2); // quadratic growth
exp = 8 * currLvl * ln(currLvl); // somewhere between linear and quadratic
It is not unusual to make first several levels exp requirement hardcoded to either ensure specific pace of first levels growth or to make first levels exp more "pretty"