Hint: You can adjust the default video playback speed in your account settings.

Importing and Initializing

In this lesson, you’ll start writing the code for your game. To start, create a new file named sky_dodge.py. Your first step will be importing pygame, and then you’ll also need to initialize it. This allows pygame to connect its abstractions to your specific hardware:

 1 # Import the pygame module
 2 import pygame
 3 
 4 # Import pygame.locals for easier access to key coordinates
 5 # Updated to conform to flake8 and black standards
 6 from pygame.locals import (
 7     K_UP,
 8     K_DOWN,
 9     K_LEFT,
10     K_RIGHT,
11     K_ESCAPE,
12     KEYDOWN,
13     QUIT,
14 )
15 
16 # Initialize pygame
17 pygame.init()

For more information about the local constants, check out the pygame documentation. For more information about the Flake8 and Black coding formatters, check out the following resources:

Comments & Discussion

Become a Member to join the conversation.