CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Level system for game

    Hi there!

    A friend an I are developing a game in which we want a level system. You start in level 1, then level 2 etc.

    The current level should be calculated from number of points the player has. The difference between two levels should increase more, as bigger level the player is.
    For example:
    Level 1: 0 - 100 points
    Level 2: 101 - 250 points
    Level 3: 251 - 450 points
    etc.

    We could write every level difference in an xml file or so, but we do not want a limit on the levels. Therefor, I would really like to know what I should do to calculate the level!

    Thank you very much!

    //Kaloer

  2. #2
    Join Date
    Oct 2006
    Posts
    616

    Re: Level system for game

    From the example you gave it seems that in order to advance from level i to level i+1, the player must gain an additional 100+(i-1)*50 points:
    example:
    Code:
    From level 1 to level 2:  100 + (1-1)*50 = 100
    From level 2 to level 3:  100 + (2-1)*50 = 150
    From level 3 to level 4:  100 + (3-1)*50 = 200
    ...
    Therefore, the total number of points required to advance from level k to level k+1 can be calculated by:
    Code:
     1 + Sum{i=1 to k} (  100 + (i-1) * 50) =
    = 1 + 100*k + 50 * Sum{i=1 to k} (i-1) = 
    = 1 + 100*k + 50*k*(k-1) / 2 =
    
    = 1 + k*(100 + 25*(k-1))
    So, for example, in order to advance from level 3 to level 4, the player must gain a total of:
    Code:
    1 + 3*(100 + 25*(3-1)) = 451 points
    Regards,
    Zachm

  3. #3
    Join Date
    Jan 2010
    Posts
    2

    Re: Level system for game

    Thank you very much! It works very good.

    //Kaloer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured