import pygame, sys from pygame.locals import * pygame.init() import time FPS = 18 # frames per second setting fpsClock = pygame.time.Clock() # set up the window DISPLAYSURF = pygame.display.set_mode((400, 300), 0, 32) pygame.display.set_caption('cat animation') pygame.mixer.music.load('plush.mp3') pygame.mixer.music.play(-1, 0.0) WHITE = (255, 255, 255) catImg = pygame.image.load('cat.png') catx = 280 caty = 220 direction = 'up' soundObj2 = pygame.mixer.Sound('gameover.wav') soundObj = pygame.mixer.Sound('beeps.wav') while True: # the main game loop DISPLAYSURF.fill(WHITE) soundObj.play() if direction == 'right': catx += 5 if catx == 280: direction = 'up' elif direction == 'down': caty += 5 if caty == 220: direction = 'right' elif direction == 'left': catx -= 5 if catx == 10: direction = 'down' elif direction == 'up': caty -= 5 if caty == 10: direction = 'left' DISPLAYSURF.blit(catImg, (catx, caty)) for event in pygame.event.get(): if event.type == QUIT: soundObj.stop() pygame.mixer.music.stop() soundObj2.play() time.sleep(3) pygame.quit() sys.exit() pygame.display.update() fpsClock.tick(FPS)