import pygame, select from socket import * # This way of writing the import statement allows you to use functions # defined in the socket library without prefixing them with # 'socket.'. So, for example, instead of writing socket.socket(...), # you can write socket(...) to create a new socket. def initialize_constants(): """ This function sets some global constants (i.e., the values of these global variables never change). """ global name name = raw_input("Please type in your name: ") pygame.init() # set up the display window global width, height, screen width = 800 height = 600 screen = pygame.display.set_mode((width,height)) # load the ballon picture global balloon balloon = pygame.image.load("red_balloon.gif") balloon = balloon.convert() global balloon2 balloon2 = pygame.image.load("green_balloon.gif") balloon2 = balloon2.convert() # load sound global pop_sound pop_sound = pygame.mixer.Sound("pop.wav") # load font global myFont myFont = pygame.font.Font(None,30) def run_game(): # initialize the balloons' positions and speeds b_x = 100 b_y = 100 b2_x = 300 b2_y = 300 # initialize the score score = 0 scorelist = [] keepGoing = True while (keepGoing): ### handle events for event in pygame.event.get(): if event.type == pygame.QUIT: keepGoing = False ### handle messages from the server # The variable in_msgs is a list. If there is a message # waiting to be received it will be of length > 0. # [in_msgs, out, err] = select.select([UDP_sock], [], [], 0) ### draw everything screen.fill(pygame.color.Color("darkblue")) # score x = 10 y = 10 label = myFont.render("Your score: "+str(score), True, pygame.color.Color("magenta")) screen.blit(label, (x,y)) # balloon images screen.blit(balloon,(int(b_x), int(b_y))) screen.blit(balloon2,(int(b2_x), int(b2_y))) pygame.display.update() def done(): global myFont myFont = None pygame.quit() def main(): initialize_constants() run_game() done() main()