php game, formula to calculate a level based on exp

前端 未结 7 2429
心在旅途
心在旅途 2020-12-23 10:34

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

7条回答
  •  悲&欢浪女
    2020-12-23 11:08

    If you wanted the following:

    • Level 1 @ 0 points
    • Level 2 @ 50 points
    • Level 3 @ 150 points
    • Level 4 @ 300 points
    • Level 5 @ 500 points etc.

    An equation relating experience (X) with level (L) is:

    X = 25 * L * L - 25 * L
    

    To calculate the level for a given experience use the quadratic equation to get:

    L = (25 + sqrt(25 * 25 - 4 * 25 * (-X) ))/ (2 * 25)
    

    This simplifies to:

    L = (25 + sqrt(625 + 100 * X)) / 50
    

    Then round down using the floor function to get your final formula:

    L = floor(25 + sqrt(625 + 100 * X)) / 50
    

    Where L is the level, and X is the experience points

提交回复
热议问题