I’m needing help figuring out logic when adding a time bonus to my game.

I only want to reward the player with extra time if they level up.

Currently when the player’s score is less than 100 no bonus is given. If the player’s score reaches 200 I want to reward the player with some bonus time.

My issue is if the score is 190 and then jumps to 210, the 200 level mark is passed and the player isn't rewarded.

If I turn on the logic to say if the score is between 190 and 210, it could reward the player at the 190, 200, 210 mark or skip from 180 to 220, bypassing the reward altogether. I have tinkered with the idea of setting a bool BonusFlag, but the same issue arises, when I set the flag.

Can anyone help provide some logic on how to overcome this obstacle?


I'm assuming you will award bonus time very some amount of points (i.e. every 100 points, starting at 200), But this can be modified to handle any type of case.

Just use integer division to check if the value has been reached and update the last awarded value when reached. For example:

// this value should be global scope (class member)
int last = 1;   // last score awarded for (initialize so that 100-199 is skipped)

if ( score / 100 > last )  {
   last++;      // only increase by ONE (prevents skipping values)

The key here is that you update the "last" value when awarding bonus score. So even if the player jumps from 100 to 300, the bonus will be awarded twice - once for the 100 points to get to 200, then again for the 100 points to get to 300.

  • \$\begingroup\$ Oooh nice! I like your idea! \$\endgroup\$ – user-44651 Apr 5 '14 at 16:38

My suggestion is that there is a moment where you are going to add points to the score. Before that instant check if the score is less than the threshold AND the score + new points is greater than it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.