Originally posted by Blizzarddog
well, uh.. i kinda deleted that part. But heres an example of what it looks like, trimmed of course.
Code:
int pexp = 0; //Player Exp.
int plevel; //player level
lu1 = 10; //level up 1
lu2 = 30;
lu3 = 50;
int main()
{
if (pexp >= lu1)
{
plevel++;
}
}
ok blizzard, if you want a "decent" level up system, you should have something like this:
Code:
#define NUMLEVELS 99 // This is the max amount of levels the character can get
int levelExp[NUMLEVELS]; //Create a huge table of all the exp
int pExp; //player's exp
int pLevel; //player's level
void testLevelUp();
void initAll();
int main()
{
initAll(); //Initialize all of the variables
// ^^ that code should be placed at the very top, outside of the game loop, because it sets up the default settings for each variable
// Here would go any other setting up
while(1) // Just making an infinite loop because I don't feel like making an entire engine, lol
{
// Now, what you want to do here is, before you go trying to test the users exp EVERY loop, only test it at the end of a battle or whatever you're using for your game
testLevelUp(); //Test if you leveled up
}
}
void initAll()
{
int b=10;
for(int a=0;a<NUMLEVELS;a++)
{
levelExp[a] = b;
b+=6;
}
//explanation of above ^^ code:
//
// This code will run through all of the levels, in this case 99
// and set up their default values
// then, you store b to the levelExp slot for the current level being
// edited, and that'll make your list of level exp's you need
// also, you need to increment the b value, otherwise it'll just keep
// making all of the values equal 10
// you may want to add something like:
// b+=rand()%10+5;
// instead of b+=6, and if you don't want it to be different every
// time, DON'T seed it, or seed it with the same thing every time
// that way it will be a little more interesting
//
pExp=0;
pLevel=0;
}
void testLevelUp()
{
if(pExp>levelExp[pLevel]) //test if the player's current exp is greater than the current level's required exp
pLevel++;
}
wow, lol, I just made all of that up off the top of my head in 10 minutes, lol, I should start making dos games again, i forgot how simple they were
well, I hope that that helps you, and anyone else who has this problem
oh, and if i didn't say earlier, the problem with your code was that you were testing if your exp was greater than level 1's requiered exp value, then add the level, therefor, say....
if you have 53 experience
and you need 20 for level 1, 36 for level 2, 57 for level 3
and you do your version of the testing, you'll level up to level 2
see what I mean? if not, just reply here again or pm me
-edit-
oh, i just noticed magos' post, he kinda mentioned the same thing, but with this one, you can actually have a lookup table of everything, and if you want it to double in exp every time like his does, just make b*=2;