Hardware Reference
In-Depth Information
The Game
Now you can get down to the game itself, which is shown in Listing 14-4.
Listing 14-4 The Slot Car Racing Game
#!/usr/bin/env python
“””
Slot Racer on the PiFace board
“””
import time # for delays
import piface.pfio as pfio # piface library
import random
import os, pygame, sys
pfio.init() # initialise pfio
pygame.init() # initialise graphics interface
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption(“SlotRacer”)
screen = pygame.display.set_mode([980,610],0,32)
background = pygame.Surface((980,610))
piSurface = pygame.Surface((555,540))
# define the colours to use for the user interface
cBackground =(255,255,255)
cLEDon = (255,0,0)
cLEDoff = (128,128,128)
cOutline = (255,128,0)
cText = (0,0,0)
cTextBack = (220,220,220)
altcText = (255,255,255)
altcTextBack = (180,180,180)
cStepBlock = (0,255,255)
# cope with not having the picture of the racing pi
try:
piPicture = ;
pygame.image.load(“racingLogo.png”).convert_alpha()
piSurface.blit(piPicture,[0,0])
except:
piSurface.fill((220,220,220)) # make just a grey area
# Set up questions
qfile = open(“questions.txt”,”r”)
questions = list()
Search WWH ::




Custom Search