Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import pygame, sys
  2. from pygame.locals import *
  3.  
  4. BLACK = (0, 0, 0)
  5. WHITE = (255, 255, 255)
  6. RED = (255, 0, 0)
  7. GREEN = (0, 255, 0)
  8. BLUE = (0, 0, 255)
  9.  
  10. x = 200
  11. y = 200
  12. sx = 1
  13. sy = 1
  14.  
  15. pygame.init()
  16. windowSurface = pygame.display.set_mode((600, 400), 0, 32)
  17. pygame.display.set_caption("Pallopeli")
  18.  
  19. while True:
  20.     pygame.draw.circle(windowSurface, BLACK, (x-sx, y-sy), 10)
  21.     if y >= 400 or y <= 0:
  22.         sy *= -1
  23.  
  24.     if x >= 600 or x <= 0:
  25.         sx *= -1
  26.  
  27.     x += sx
  28.     y += sy
  29.  
  30.     pygame.draw.circle(windowSurface, WHITE, (x, y), 10)
  31.     pygame.display.update()
  32.  
  33. while True:
  34.     for event in pygame.event.get():
  35.         if event.type == QUIT:
  36.             pygame.quit()
  37.             sys.exit()
Add Comment
Please, Sign In to add comment