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))
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:
PlayerLife = PlayerLife + (Points/1000)
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
how's that for being clever;)
PlayerLife += Points/1000
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.
int score 1000;
lives = 3;
if((score % 1000) == 0)
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.
int Life = 3;
int Score = 0;
int ScoreToGetLife = 1000;
if(Score >= ScoreToGetLife)
ScoreToGetLife += 1000;
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.