It’s fairly common for arcade games like this to start off easy and get harder over time. You could spawn asteroids more frequently and/or faster asteroids the longer the user stays alive.

Task Definition

  • Asteroids should spawn faster over time. Perhaps start the same with asteroids spawning every 2.5 seconds and then have the time between asteroids spawning reduce every so often as the player continue the game.
  • You could also add an increasing variable to the initial velocity of asteroids that spawn over time. i.e. If your asteroids start spawning at “Velocity 200” then every time an asteroid is destroyed, you could add one to that value.
  • If you have previously given asteroids health from another side quest, you could give asteroids that spawn later in the game more health.

Hints

In the default version of the game, every time a new asteroid appears we reset the asteroidTimer to 3000ms (3 seconds). Instead of always re-setting this value to 3000, you could to the following;

  • Add a variable in your create() function called something like this.timeBetweenAsteroids and set it to 3000.
  • Every time you spawn a new asteroid, instead of using the fixed value of 3000, use the variable this.timeBetweenAsteroids.
  • Also, whenever you create a new asteroid, you should reduce this.timeBetweenAsteroids by 50.

Solution

Here is one way that you might solve this task…

Add the following lines of code in MainGameScene.js...

create() {
	this.timeBetweenAsteroids = 3000;
}

update() {
	if ( this.asteroidTimer < 0 ) {      
		this.createAsteroid();
		this.asteroidTimer = this.timeBetweenAsteroids;

		if ( this.timeBetweenAsteroids > 1000 ) {
			this.timeBetweenAsteroids = this.timeBetweenAsteroids - 20;
		}
	}
}