Passing False to set_visible() tells Pygame to hide the cursor when the
mouse is over the game window.
We’ll make the cursor reappear once the game ends so the player can
click Play again to begin a new game. Here’s the code to do that:
alien_invasion.py def _ship_hit(self):
"""Respond to ship being hit by alien."""
if [Link].ships_left > 0:
--snip--
else:
self.game_active = False
[Link].set_visible(True)
We make the cursor visible again as soon as the game becomes inactive,
which happens in _ship_hit(). Attention to details like this makes your game
more professional looking and allows the player to focus on playing, rather
than figuring out the user interface.
TRY IT YOURSELF
14-1. Press P to Play: Because Alien Invasion uses keyboard input to control the
ship, it would be useful to start the game with a keypress. Add code that lets the
player press P to start. It might help to move some code from _check_play_button()
to a _start_game() method that can be called from _check_play_button() and
_check_keydown_events().
14-2. Target Practice: Create a rectangle at the right edge of the screen that
moves up and down at a steady rate. Then on the left side of the screen, cre-
ate a ship that the player can move up and down while firing bullets at the
rectangular target. Add a Play button that starts the game, and when the player
misses the target three times, end the game and make the Play button reappear.
Let the player restart the game with this Play button.
Leveling Up
In our current game, once a player shoots down the entire alien fleet, the
player reaches a new level, but the game difficulty doesn’t change. Let’s
liven things up a bit and make the game more challenging by increasing
the game’s speed each time a player clears the screen.
Modifying the Speed Settings
We’ll first reorganize the Settings class to group the game settings into
static and dynamic ones. We’ll also make sure any settings that change
Scoring 283