Advertisement
Guest User

Bouncing cat

a guest
Mar 15th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import pygame, sys
  2. from pygame.locals import *
  3.  
  4. pygame.init()
  5. DISPLAYSURF = pygame.display.set_mode((400,300))
  6. FPS = 30
  7. fpsClock = pygame.time.Clock()
  8. pygame.display.set_caption('Bouncing Cat')
  9.  
  10. WHITE = pygame.Color(255,255,255)
  11. GREEN = pygame.Color(0,255,0)
  12. BLUE = pygame.Color(0,0,255)
  13. RED = pygame.Color(255,0,0)
  14. BLACK = pygame.Color(0,0,0)
  15.  
  16. cat = pygame.image.load('cat.png')
  17. speed = [5,5]
  18. catx, caty = 200, 150
  19.  
  20. while True:
  21.     DISPLAYSURF.fill(WHITE)
  22.     for event in pygame.event.get():
  23.         if event.type == QUIT:
  24.             pygame.quit()
  25.             sys.exit()
  26.         if event.type == KEYDOWN:
  27.             if event.key == K_ESCAPE:
  28.                 pygame.quit()
  29.                 sys.exit()
  30.  
  31.  
  32.     if cat.get_rect().right >= 400 or cat.get_rect().left <= 0:
  33.         speed[0] = -speed[0]
  34.     if cat.get_rect().bottom >= 300 or cat.get_rect().top <= 0:
  35.         speed[1] = -speed[1]
  36.    
  37.     catx += speed[0]
  38.     caty += speed[1]
  39.  
  40.     DISPLAYSURF.blit(cat,(catx,caty))
  41.     pygame.display.update()
  42.     fpsClock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement