Advertisement
Guest User

main.py

a guest
May 17th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement