Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building an RPG game system in Java, and one part is the leveling system, with the following:

max_exp: maximum experience points

max_level: maximum level

Given a level, find the minimum experience points required:

exp = max_exp / 2^(max_level-level)

Then, given experience points count, find current level:

level = max_level - (log2(max_exp) - log2(exp))

My code in Java:

class LevelSystem
    // maximum experience points
    public long max_exp;

    // maximum level
    public short max_level;

    // get a level minimum exp
    public long getExperience (short level)
        return Math.ceil((double)max_exp / Math.pow(2, max_level-level));

    // get current level
    public short level getLevel (long exp)
        return Math.floor((double)max_level - (Math.log2(max_exp) - Math.log2(exp)));

So, is my method valid in general ?

And, are there better ways to form a leveling scale ?

share|improve this question

closed as too broad by Josh Petrie Dec 4 '13 at 6:11

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

There are very many ways to do leveling scales, very very many. Which one is best depends on entirely on your game. – Sean Middleditch Jul 18 '13 at 23:21
@SeanMiddleditch my game genre is exp-based action RPG .. can you link me to where I can find different leveling scales with code ? – Khaled.K Jul 19 '13 at 21:35
No, I cannot. Just make your game, tweak the numbers based on testing and feedback. Find an answer that works for you, not an answer that worked for a different game. If you're really that worried about it, it's not hard to search for XP tables for most games and copy what they did (quite a few use hand-tweaked tables, not algorithms). – Sean Middleditch Jul 19 '13 at 21:38