-
increasing players life
In my game I would like it so that every 1000pts the players life increases by one.
if((player.score % 1000) == 0))
player.life++;
Would this be the correct way to write the condition?
Also, how do I make it so that the player's life only increases when they do have a 1000pts? And not to have their lives continue to increase until
their score changes.
-
I believe you just want to do this:
Code:
PlayerLife = PlayerLife + (Points/1000)
- Sean
-
Another way to do it is to set a counter, when the counter reaches 1000 add 1 to the life and reset the counter. But that would be pretti much a waste of mem.
Oh sean clever stuff...
-
or even better yet
Code:
PlayerLife += Points/1000
how's that for being clever;)
-
Code:
int score 1000;
lives = 3;
while(1)
{
getInput();
if((score % 1000) == 0)
lives++;
score++;
}
You code would work, but all I want to do is keep the score the same and just add to lives. And about the other problem is that if the score is 1000 and there is no input or change, lives continues to increase which I don't want to happen either.
Hope this makes things more clear.
-
Simple, use another variable to keep track on how much score you need to get an extra life, then increase it by 1000 when getting a life.
Code:
int Life = 3;
int Score = 0;
int ScoreToGetLife = 1000;
void CheckForExtraLife()
{
if(Score >= ScoreToGetLife)
{
Life++;
ScoreToGetLife += 1000;
}
}
<edit>
If there is something in your game that gives more than 1000 points, you can change the if to a while, so you gain all lives at once instead one per time the function runs.
</edit>