How do I really calculate level progress using an algorithm?

in my application I get var $curxp , which contains an int, now I want to create a function that automatically returns $xplvlup (which contains an int, how much XP is needed for the next level and a function that returns the current level.

Now I can just specify hardcode with switch statements and calculated numbers, for example:

 switch($curxp){ case <10: $xplvlup = 10; break; } 

But it would be much better if I could use the algorithm, so that there is no maximum level. I know that I need to work with exhibitors to get a good curve, but I just don’t know how to get started.

UPDATE

Thanks to Oltarus, I came to the following solution:

 $curxp = 20; function level($lvl){ return $xp = pow($lvl,2) + 5 * $lvl; } $lvl = 0; while (level($lvl) < $curxp) $lvl++; $totxp = level($lvl); $xplvlup = level($lvl) - $curxp; echo 'Level: '.$lvl."<br />"; echo 'Total XP: '.$totxp."<br />"; echo 'XP needed for Levelup: '.$xplvlup; 
+4
source share
2 answers

I don’t know how you calculate the levels, but let me say that you have a level($n) function that returns the amount of XP needed for the $n level.

 $n = 0; while (level($n) < $curxp) $n++; $xplvlup = level($n) - $curxp; 
+1
source

If, for example, the first level requires 500 xp, and then at each level you need 10% more xp, you can do something like this:

 function xp_needed($cur_lvl){ $start = 500; return $start*pow(1.1,($cur_lvl-1)); } 

For each level, xp is calculated at 500 * 1.1^(level-1)

Edit

Inputs $cur_lvl must be subtracted by 1.

+2
source

All Articles