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