import pygame def run_game(): ## Initialize the pygame submodules and set up the display window. pygame.init() width = 640 height = 480 game_window = pygame.display.set_mode((width,height)) # load the images and convert into Pygame's internal image format guy_pics = [pygame.image.load("WalkingSquare1.gif"), pygame.image.load("WalkingSquare2.gif"), pygame.image.load("WalkingSquare3.gif"), pygame.image.load("WalkingSquare4.gif"), pygame.image.load("WalkingSquare5.gif")] for index in range(0,len(guy_pics)): guy_pics[index] = guy_pics[index].convert() guy_x = 100 guy_y = 100 anim_counter = 0 anim_threshold = 70 cur_idx = 0 ## The game loop starts here. keepGoing = True while (keepGoing): ## Handle events. for event in pygame.event.get(): if event.type == pygame.QUIT: keepGoing = False anim_counter += 1 if anim_counter > anim_threshold: cur_idx = (cur_idx + 1) % 5 anim_counter = 0 ## Draw picture and update display game_window.fill(pygame.color.Color("yellowgreen")) game_window.blit(guy_pics[cur_idx],(guy_x,guy_y)) pygame.display.update() ## The game loop ends here. pygame.quit() ## Call the function run_game. run_game()