daily pastebin goal
4%
SHARE
TWEET

main.py

a guest May 17th, 2018 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame_sdl2
  2. pygame_sdl2.import_as_pygame()
  3. import sys
  4. import pygame
  5. from pygame.locals import *
  6.  
  7. pygame.init()
  8. # Resolution is ignored on Android
  9. surface = pygame.display.set_mode((640, 480))
  10.  
  11. ball = pygame.image.load(".jpg")
  12. ballrect = ball.get_rect()
  13. clock = pygame.time.Clock()
  14.  
  15. width = surface.get_width()
  16. height = surface.get_height()
  17.  
  18. speed = [4, 4]
  19. while True:
  20.     for ev in pygame.event.get():
  21.         if ev.type == QUIT:
  22.             pygame.quit()
  23.     clock.tick(60)
  24.     surface.fill((0, 0, 0))
  25.     ballrect = ballrect.move(speed)
  26.     if ballrect.left < 0 or ballrect.right > width:
  27.         speed[0] = -speed[0]
  28.     if ballrect.top < 0 or ballrect.bottom > height:
  29.         speed[1] = -speed[1]
  30.     surface.blit(ball, ballrect)
  31.     pygame.display.flip()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top