RPG XP Generator via Javascript
Javascript generating RPG Experience Points... I was talking with Jay from RampantGames a little bit about how do games generate their XP requirements. It's usually pretty easy to get to level 5 or so but it gets progressively harder after that. Jay gave me a great simple algorithm to use and I whipped up a little javascript app to generate XP requirements for each level up. I'm not sure how useful this may be to you, but if you are doing any RPG development you might be like me and wonder how to create the gradual increase in difficulty...
If you have another algorithm, or a way I can improve on this, please leave a comment!



2 Comments:
To get all nerdy about it, this is just a second-order arithmetic sequence. In fact, it's a constant times the Triangular Numbers, solved by the Polygonal Number formula. If you wanted to figure out the XP for level 100 in constant time rather than a for loop that runs 100 times, just use the following formula:
totalXP = baseXP*(level*(level - 1)/2)
so for level 100 at 20 base XP:
lvl100XP = 20*100*99/2 = 99,000
(the same result as the 100th iteration of your loop).
Hope that helps!
Very cool! I'm going to revise the code to do that instead. Thanks for your helpful comment!
Post a Comment
<< Home