import pygame import random def run_game(): ## 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 (images, sounds, ...) guy = pygame.image.load("WalkingSquare1.gif") guy = guy.convert() # initialize the guy's position and speed g_x = 100 g_y = 100 g_speed_x = 0 g_speed_y = 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 ## Update game objects g_x = g_x + g_speed_x g_y = g_y + g_speed_y ## Draw picture and update display my_win.fill(pygame.color.Color("green")) # put image in the picture at the desired location my_win.blit(guy,(g_x,g_y)) pygame.display.update() ## The game loop ends here. pygame.quit() ## Call the function run_game. run_game()