Wouldn’t it be easier to just add a modifier that determine the current max-xp value? Something like:
private const float XP_MODIFIER = .33f;
private float _curXp; //Currently attained xp
private float _xpToLvl; //Target xp to gain before leveling up
private int _lvl; //current character level
public void GainXP( float f ) {
_curXp += f;
if( _curXp >= _xpToLvl ) {
OnDing();
}
}
public void OnDing() {
_lvl++;
float nextCap = _xpToLvl + ( _xpToLvl * XP_MODIFIER ); //Increase target XP value by 33% of it's previous value
_xpToLvl = nextCap;
}
I wasn’t really looking for a method that levels up the character, but rather I’m making a database manager in where you create a character and choose his/her starting lvl, so lvl is the thing that you select, and then it will start the character off at the beginning of that lvl.
So the programmer in me wants to do something like this (I’m terrible at math as you can tell):
int startingExperience = 0;
for (int x = 0; x < startingLvl; x++) {
startingExperience += x * 100;
}
//result is our starting experience per lvl.
//then toNext:
int toNext = startingExperience + (startingLvl * 100);
I’m very simple minded and know nothing of logarithmic curves but this seems to create one in the simplest way I can think of.
I see things like this:
y = (x ^ 2)
…and have no clue how to implement it! It makes me feel like a noob.
I feel like he’s making this far more complicated for himself than necessary and I’m not quite sure what he’s getting at with this code which would explain why he’s struggling.
Have you checked out this tutorial? I would start from scratch and use this.