during the game reset when we start a new game.
Here’s the __init__()
method for settings.py:
settings.py def __init__(self):
"""Initialize the game's static settings."""
# Screen settings
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230, 230, 230)
# Ship settings
self.ship_limit = 3
# Bullet settings
self.bullet_width = 3
self.bullet_height = 15
self.bullet_color = 60, 60, 60
self.bullets_allowed = 3
# Alien settings
self.fleet_drop_speed = 10
# How quickly the game speeds up
1 self.speedup_scale = 1.1
2 self.initialize_dynamic_settings()
We continue to initialize settings that stay constant in the __init__()
method. We add a speedup_scale setting 1 to control how quickly the game
speeds up: a value of 2 will double the game speed every time the player
reaches a new level; a value of 1 will keep the speed constant. A value like
1.1 should increase the speed enough to make the game challenging but
not impossible. Finally, we call the initialize_dynamic_settings() method
to initialize the values for attributes that need to change throughout the
game 2.
Here’s the code for initialize_dynamic_settings():
settings.py def initialize_dynamic_settings(self):
"""Initialize settings that change throughout the game."""
self.ship_speed = 1.5
self.bullet_speed = 2.5
self.alien_speed = 1.0
# fleet_direction of 1 represents right; -1 represents left.
self.fleet_direction = 1
This method sets the initial values for the ship, bullet, and alien
speeds. We’ll increase these speeds as the player progresses in the game
and reset them each time the player starts a new game. We include fleet
_direction in this method so the aliens always move right at the beginning
of a new game. We don’t need to increase the value of fleet_drop_speed,
284 Chapter 14