I was curious on how level was determined for games and I found an awesome article about it by Jake Lee.
But one important thing was not explained in this article, how is it implemented in JavaScript?!
He has provided implementations in a Google Sheet and Github Gist though. So that may be your preferred method.
A simple format of the formulas:
XP = (level / x) ** y
level = x * Math.pow(xp, 1 / y)
The JavaScript implementation:
const getXp = (level, x, y) => Math.round((level / x) ** y);
const getLevel = (xp, x, y) => x * Math.pow(xp, 1 / y);
x
affecting the amount of XP (lower values = more XP required per level), and
y
being how quickly the required xp per level should increase (higher values = larger gaps between levels)
I created a simple app to see the pace your XP calculating formula. You can add addition x
and y
values to compare them with. (see index.html
)