Advertisement
cookertron

Pydroid example

Dec 27th, 2019
803
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 pygame
  4. import sys
  5.  
  6. # define some colors
  7. BLACK = (0, 0, 0)
  8. WHITE = (255, 255, 255)
  9.  
  10. # set up pygame
  11. pygame.init()
  12. DS = pygame.display.set_mode((640, 480))
  13. CLOCK = pygame.time.Clock()
  14.  
  15. # frame per second
  16. FPS = 120
  17.  
  18. # you can't set the width and height of the pygame window, it's
  19. # fullscreen by default so you need to get the dimensions
  20. W = DS.get_width()
  21. H = DS.get_height()
  22. HW, HH = int(W / 2), int(H / 2)
  23.  
  24. x = 0
  25. dx = 4 # change this value to make the ball go faster or slower
  26.  
  27. while True:
  28.     e = pygame.event.get()
  29.    
  30.     pygame.draw.circle(DS, WHITE, (x, HH), 30)
  31.    
  32.     x += dx
  33.     if x > W or x < 0:
  34.         dx = -dx
  35.         x += dx
  36.    
  37.     pygame.display.update()
  38.     DS.fill(BLACK)
  39.     CLOCK.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement