Game speed after certain score is reached

Hi there, I am creating a game where the player has to avoid some asteriods, and gain a good score. After going past a certain score, the game speed increases. At the moment i have this

  playerScore.countUp();
  textAlign(LEFT);
  text("Score: " +round(playerScore.getGameScore()), textX, textY);
  if (playerScore.getGameScore() == 500)
  {
    spaceRock1.ySpeed += .5;
  } else if (playerScore.getGameScore() == 1000)
  {
     spaceRock1.ySpeed += 1;
  }

But i dont want to have like a massive if statement for loads of values really. Would there be a way to create a statement to say that if the score is equal to a certain numbr, increase the game speed by a certain amount each time that number is hit

1 Like

Yes. Put the limits and the increments in two arrays, and use a loop.

int[] min_limits = { 500, 1000, 1500, 1750, 1800, 1950, 2000 };
int[] increments = { 0.5, 1, 2, 3, 4, 8, 16 };
float inc = 0;
for( int i = 0; i < min_limits.length; i++ ){
  if( score > min_limits[i] ){
    inc = increments[i];
  }
}
speed += inc;
1 Like

thank you :slight_smile: that works but when it reaches the first score, it just keeps speeding up without it going up in increments when each score limit is hit if that makes sence ?

Am i doing something wrong for it to be doing that ?

Your objects (asteroids, I assume) have a position that changes each frame. That is, each frame, you add their speed to their position.

When a certain score is reached, you want to set a new speed. Not just add some amount to it, but assign it a new value. In short, you probably want speed = inc;, not speed += inc;. See the difference?

If you kept adding an increment to their speed every frame, the asteroids wouldn’t just go faster, they would KEEP going faster, because the speed they’re getting added to their position would keep increasing. Acceleration!

1 Like

Thanks so much ! it works how i want it now :slight_smile: again, many thanks :slight_smile: