# Game speed after certain score is reached

**URL:** <https://discourse.processing.org/t/game-speed-after-certain-score-is-reached/19043>\
**Category:** Coding Questions\
**Created:** [March 26, 2020, 4:23pm UTC](https://discourse.processing.org/t/game-speed-after-certain-score-is-reached/19043 "2020-03-26T16:23:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Banana132](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@Banana132](https://discourse.processing.org/u/Banana132)\
**Post date:** [March 26, 2020, 4:23pm UTC](https://discourse.processing.org/t/game-speed-after-certain-score-is-reached/19043/1 "2020-03-26T16:23:43Z")

</div>

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

```auto
  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

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 26, 2020, 4:28pm UTC](https://discourse.processing.org/t/game-speed-after-certain-score-is-reached/19043/2 "2020-03-26T16:28:39Z")

</div>

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

```auto
int[] min_limits = { 500, 1000, 1500, 1750, 1800, 1950, 2000 };
int[] increments = { 0.5, 1, 2, 3, 4, 8, 16 };

```

```auto
float inc = 0;
for( int i = 0; i < min_limits.length; i++ ){
  if( score > min_limits[i] ){
    inc = increments[i];
  }
}
speed += inc;

```

---

<div class="post-metadata">

**Author:** ![Banana132](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@Banana132](https://discourse.processing.org/u/Banana132)\
**Post date:** [March 26, 2020, 4:37pm UTC](https://discourse.processing.org/t/game-speed-after-certain-score-is-reached/19043/3 "2020-03-26T16:37:14Z")

</div>

thank you 🙂 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 ?

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 26, 2020, 9:26pm UTC](https://discourse.processing.org/t/game-speed-after-certain-score-is-reached/19043/4 "2020-03-26T21:26:26Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Banana132](https://avatars.discourse-cdn.com/v4/letter/b/d9b06d/32.png) [@Banana132](https://discourse.processing.org/u/Banana132)\
**Post date:** [March 26, 2020, 10:16pm UTC](https://discourse.processing.org/t/game-speed-after-certain-score-is-reached/19043/5 "2020-03-26T22:16:28Z")

</div>

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