• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Leveling algorithms

D

Doooooli

Guest
I need some math help with a leveling algorithm I'm writing atm! or well maybe I don't need as much help with the algorithm itself, but rather answer to a question! is there anyway to force the exp needed for each level to be set without using a lot of variables in an algorithm?

so basically instead of having

level1need = 20
level2need = 30
level3need = 40

etc etc etc, would it be possible to fit all that in an algorithm? the max cap for my "game" is atm 25, so it's no biggie if I need to write 25 variables, it's just tedious :p
 

Simon Gust

Member
Make a variable called "level_need" and set it to 20.
Everytime you reach that number, not only increase your level by 1, also increase that number by say 10.
Important here is that you subtract level_need from current_exp before you increase level_need at level up.
This way players don't get cheated out of expierience.
Code:
if (cur_exp >= level_need)
{
 cur_exp -= level_need;
 cur_level += 1;
 level_need += 10;

 // increase stats or something here
}
If you want gradual scaling, use cur_level to modify how much to level_need is added ->
Code:
level_need += 10 * cur_level;
for example.
 
D

Doooooli

Guest
Make a variable called "level_need" and set it to 20.
Everytime you reach that number, not only increase your level by 1, also increase that number by say 10.
Important here is that you subtract level_need from current_exp before you increase level_need at level up.
This way players don't get cheated out of expierience.
Code:
if (cur_exp >= level_need)
{
 cur_exp -= level_need;
 cur_level += 1;
 level_need += 10;

 // increase stats or something here
}
If you want gradual scaling, use cur_level to modify how much to level_need is added ->
Code:
level_need += 10 * cur_level;
for example.
Oh cool, that will definitely work for now!

but there's no way to choose for yourself what exp should be needed without all of those 25 variables?
cause I made my own xp chart, and this is how I would like it to be!

xp needed for each level
1 = 80
2 = 170
3 = 270
4 = 380
5 = 510
6 = 650
7 = 800
8 = 970
9 = 1150
10 = 1360
11 = 1580
12 = 1830
13 = 2110
14 = 2410
15 = 2750
16 = 3120
17 = 3520
18 = 3970
19 = 4470
20 = 5020
21 = 5620
22 = 6290
23 = 7030
24 = 7840
25 = 8740
 

Simon Gust

Member
Oh cool, that will definitely work for now!

but there's no way to choose for yourself what exp should be needed without all of those 25 variables?
cause I made my own xp chart, and this is how I would like it to be!
An elegant solution would be to use an array, then you only have to remember 1 variable name, and the values are given with cur_level.
Code:
required_exp[0] = 0;
required_exp[1] = 80;
required_exp[2] = 170;
required_exp[3] = 270;
etc. until 25
Then when asking how much exp is needed
Code:
var exp_needed = required_exp[cur_level];
if (cur_exp >= exp_needed)
{
 cur_exp -= exp_needed;
 cur_level += 1;

 // level up stuff

}
 
D

Doooooli

Guest
An elegant solution would be to use an array, then you only have to remember 1 variable name, and the values are given with cur_level.
Code:
required_exp[0] = 0;
required_exp[1] = 80;
required_exp[2] = 170;
required_exp[3] = 270;
etc. until 25
Then when asking how much exp is needed
Code:
var exp_needed = required_exp[cur_level];
if (cur_exp >= exp_needed)
{
 cur_exp -= exp_needed;
 cur_level += 1;

 // level up stuff

}
Thank you! that worked like a charm
 
T

tserek

Guest
Looping is an option if you don't like to write all the exp needed, but i see there must be reason bacause the exp table doesn't seem to follow any logic.

so at create event:
Code:
cur_exp=0;
cur_level=1;
max_level=25;

var need,a;
need=80;

for (a=2; a<(max_level+2); a+=1)
{
 exp_need[a] = need;
 need += 80 + (a-1)*10; // result 80, 170, 270, 380, 500...
}
and at step event:
Code:
if cur_exp >= exp_need[cur_level+1]
{
 if cur_level < max_level {cur_level +=1;}
}
 
Last edited by a moderator:

Simon Gust

Member
Looping is an option if you don't like to write all the exp needed, but i see there must be reason bacause the exp table doesn't seem to follow any logic.

so at create event:
Code:
cur_exp=0;
cur_level=1;
max_level=25;

var need,a;
need=80;

for (a=2; a<(max_level+2); a+=1)
{
 exp_need[a] = need;
 need += 80 + (a-1)*10; // result 80, 170, 270, 380, 500...
}
and at step event:
Code:
if cur_exp >= exp_need[cur_level+1]
{
 if cur_level < max_level {cur_level +=1;}
}
Design choice I guess.
I remember playing a mobile game where required exp didn't have much logic, but some levels had larger gaps than others in a sense to achieve this kind of "important level reached" feeling. To set a benchmark maybe.
For my game I use solely math.
 
Z

zendraw

Guest
so what about an algorithm for levelling? that also scales the xp rq
 
Z

zendraw

Guest
i mean in a unpredictable manner. people culd easily notice that every next level you need 1.5 times more xp. and mystery is what is exciting in a game imo.
 

Simon Gust

Member
i mean in a unpredictable manner. people culd easily notice that every next level you need 1.5 times more xp. and mystery is what is exciting in a game imo.
So you mean random values in a reasonable manner? I could see something like simplex noise, generating req exp in a seeded regulation.
Or like an algorithm that is always the same but extremely hard to encrypt and in the end it turns out it's just hand-crafted?
 
Top