Hardware Reference
In-Depth Information
Listing 6-7 continued
screenOffset, 12 + pieMan),0)
pygame.draw.rect(screen, cBackground, (playWidth + ;
screenOffset,285, screenOffset, 12 + pieMan),0)
pygame.display.update()
def updateLives():
for pie in range(0,maxLives) :
screen.blit(piPicture[2],[25,348+pie*80])
if pie >=lives:
y = 396 + (pie * 80)
pygame.draw.line(screen,(255,255,0),(25,y),;
(25+pieMan, y-pieMan),8)
def updateScore(toAdd):
global score
score += toAdd
drawWords(str(score),1,textHeight)
his is quite simple to follow. First the background is blited into the screen and then the pills
layer, followed by the picture of Pie Man. Note here that all the sprites are held in an array,
and the one chosen is given by the direction number along with the animation bit, which is
toggled by the variable step . his simple method ensures that the sprite chosen is in the
correct direction and alternates with the pie lid open and closed. his gives a nice chomping
efect. Next the two ghosts are drawn. During a power play they are the blue versions; other-
wise, they are the red and orange ones. he individual ghost sprite used is determined by the
global variable gStep and is altered in the main function, along with Pie Man's step vari-
able. Finally, the ends of the tunnels are blanked out in case Pie Man is making a trip through
them, which makes it look like he is disappearing through the tunnel. he two other func-
tions also update the screen but are called only occasionally. he updateLives function
draws a number of Pie Man images on the left of the screen and draws a thick strikethrough
line across one if that life has been spent. he updateScore function simply takes in a
number, adds it to the total score and then draws that score on the screen.
Before you reach the main function that brings it all together and deines the game you must
add the usual housekeeping functions. hese are shown in Listing 6-8.
Listing 6-8 Housekeeping Functions
def terminate(): # close down the program
print (“Closing down please wait”)
pygame.quit() # close pygame
 
Search WWH ::




Custom Search