php game, formula to calculate a level based on exp

user880356 picture user880356 · Aug 5, 2011 · Viewed 26.5k times · Source

Im making a browser based PHP game and in my database for the players it has a record of that players total EXP or experience.

What i need is a formula to translate that exp into a level or rank, out of 100.

So they start off at level 1, and when they hit say, 50 exp, go to level 2, then when they hit maybe 125/150, level 2.

Basically a formula that steadily makes each level longer (more exp)

Can anyone help? I'm not very good at maths :P

Answer

Vilx- picture Vilx- · Aug 5, 2011

Many formulas may suit your needs, depending on how fast you want the required exp to go up.

In fact, you really should make this configurable (or at least easily changed in one central location), so that you can balance the game later. In most games these (and other) formulas are determined only after playtesting and trying out several options.

Here's one formula: First level-up happens at 50 exp; second at 150exp; third at 300 exp; fourth at 500 exp; etc. In other words, first you have to gather 50 exp, then 100 exp, then 150exp, etc. It's an Arithmetic Progression.

For levelup X then you need 25*X*(1+X) exp.

Added: To get it the other way round you just use basic math. Like this:

y=25*X*(1+X)
0=25*X*X+25*X-y

That's a standard Quadratic equation, and you can solve for X with:

X = (-25±sqrt(625+100y))/50

Now, since we want both X and Y to be greater than 0, we can drop one of the answers and are left with:

X = (sqrt(625+100y)-25)/50

So, for example, if we have 300 exp, we see that:

(sqrt(625+100*300)-25)/50 = (sqrt(30625)-25)/50 = (175-25)/50 = 150/50 = 3

Now, this is the 3rd levelup, so that means level 4.