Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys
- from pygame.locals import *
- pygame.init()
- DISPLAYSURF = pygame.display.set_mode((400,300))
- FPS = 30
- fpsClock = pygame.time.Clock()
- pygame.display.set_caption('Bouncing Cat')
- WHITE = pygame.Color(255,255,255)
- GREEN = pygame.Color(0,255,0)
- BLUE = pygame.Color(0,0,255)
- RED = pygame.Color(255,0,0)
- BLACK = pygame.Color(0,0,0)
- cat = pygame.image.load('cat.png')
- speed = [5,5]
- catx, caty = 200, 150
- while True:
- DISPLAYSURF.fill(WHITE)
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- if event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- pygame.quit()
- sys.exit()
- if cat.get_rect().right >= 400 or cat.get_rect().left <= 0:
- speed[0] = -speed[0]
- if cat.get_rect().bottom >= 300 or cat.get_rect().top <= 0:
- speed[1] = -speed[1]
- catx += speed[0]
- caty += speed[1]
- DISPLAYSURF.blit(cat,(catx,caty))
- pygame.display.update()
- fpsClock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement