Hardware Reference
In-Depth Information
Prepare for lift off
As menioned earlier, this project is based on the topic Making Games with Python &
Pygam e ( http://inventwithpython.com/makinggames.p df ). In this task, we will
go through select features of the pygame module. It is important that you familiarize
yourself with the different features available under the pygame module.
Engage thrusters
1.
We will get started by imporing the modules required for the Hello world example.
We will import the pygame and the sys module:
import pygame,sys
2.
Next, we will also import pygame.locals , since it contains several constant variables:
from pygame.locals import *
3. In order to make use of the funcions of the pygame module, we need to iniialize
the module:
pygame.init()
4. We will set the window width and height parameters and create a pygame.
Surface object that is stored in a variable called DISPLAYSURF :
DISPLAYSURF = pygame.display.set_mode((400, 300))
5. We will set the window itle name:
pygame.display.set_caption('Hello World!')
6. Now, we will run a loop that waits for events inside the window and update the
display through every cycle. In this example, we do not have anything to be updated.
We will quit the program when the user closes the window:
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
7. This should open up a blank window itled Hello World .
 
Search WWH ::




Custom Search