import pygame, select import socket def run_game(): name = raw_input ("What is your name? ") ## Initialize the pygame submodules and set up the display window. pygame.init() width = 640 height = 480 my_win = pygame.display.set_mode((width,height)) ## Load resources balloon = pygame.image.load("red_balloon.gif") balloon = balloon.convert() balloon2 = pygame.image.load("green_balloon.gif") balloon2 = balloon2.convert() pop_sound = pygame.mixer.Sound("pop.wav") myFont = pygame.font.Font(None,30) ## Initialize game objects # socket and server address # create socket and define server address # balloon positions b_x = 100 b_y = 100 b2_x = 300 b2_y = 300 score = 0 scorelist = [] ## The game loop starts here. keepGoing = True while (keepGoing): ## Handle events. for event in pygame.event.get(): if event.type == pygame.QUIT: keepGoing = False # what happens when the mouse gets clicked? ## Update game objects # 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 picture and update display my_win.fill(pygame.color.Color("darkblue")) # score x = 10 y = 10 label = myFont.render("Your score: "+str(score), True, pygame.color.Color("magenta")) my_win.blit(label, (x,y)) # draw the list of scores received from the server # balloon images my_win.blit(balloon,(int(b_x), int(b_y))) my_win.blit(balloon2,(int(b2_x), int(b2_y))) pygame.display.update() ## The game loop ends here. myFont = None # send disconnect message and close socket pygame.quit() ## Call the function run_game. run_game()