because when the aliens move faster across the screen, they’ll also come
down the screen faster.
To increase the speeds of the ship, bullets, and aliens each time the
player reaches a new level, we’ll write a new method called increase_speed():
settings.py def increase_speed(self):
"""Increase speed settings."""
self.ship_speed *= self.speedup_scale
self.bullet_speed *= self.speedup_scale
self.alien_speed *= self.speedup_scale
To increase the speed of these game elements, we multiply each speed
setting by the value of speedup_scale.
We increase the game’s tempo by calling increase_speed() in _check
_bullet_alien_collisions() when the last alien in a fleet has been shot down:
alien_invasion.py def _check_bullet_alien_collisions(self):
--snip--
if not self.aliens:
# Destroy existing bullets and create new fleet.
self.bullets.empty()
self._create_fleet()
self.settings.increase_speed()
Changing the values of the speed settings ship_speed, alien_speed, and
bullet_speed is enough to speed up the entire game!
Resetting the Speed
Now we need to return any changed settings to their initial values each time
the player starts a new game; otherwise, each new game would start with
the increased speed settings of the previous game:
alien_invasion.py def _check_play_button(self, mouse_pos):
"""Start a new game when the player clicks Play."""
button_clicked = self.play_button.rect.collidepoint(mouse_pos)
if button_clicked and not self.game_active:
# Reset the game settings.
self.settings.initialize_dynamic_settings()
--snip--
Playing Alien Invasion should be more fun and challenging now. Each
time you clear the screen, the game should speed up and become slightly
more difficult. If the game becomes too difficult too quickly, decrease the
value of settings.speedup_scale. Or if the game isn’t challenging enough,
increase the value slightly. Find a sweet spot by ramping up the difficulty in
a reasonable amount of time. The first couple of screens should be easy, the
next few should be challenging but doable, and subsequent screens should
be almost impossibly difficult.
Scoring 285