Guest User

Untitled

a guest
Dec 5th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. import pygame, random, time
  2.  
  3. RUNNING = True
  4. WIDTH = 640
  5. HEIGHT = 480
  6.  
  7. RED = 255, 0, 0
  8. GREEN = 0, 255, 0
  9. BLUE = 0, 0, 255
  10. BLACK = 0, 0, 0
  11. WHITE = 255, 255, 255
  12.  
  13. CHARPOS = [320, 384]
  14. OBSTACLE = [175, 20, 50, 50]  # This is now a list so we can edit it later
  15.  
  16. FPS = 30
  17.  
  18. CLOCK = pygame.time.Clock()
  19.  
  20. def DRAWRECT():  # We don't create anything, we draw.
  21.     pygame.draw.rect(SURFACE, BLUE, OBSTACLE)
  22.  
  23.  
  24. SURFACE = pygame.display.set_mode((WIDTH, HEIGHT))
  25. pygame.display.set_caption("SIDEY SIDE GAME")
  26.  
  27. try:
  28.     while RUNNING:
  29.         for event in pygame.event.get():
  30.             if event.type == pygame.QUIT:
  31.                 RUNNING = False
  32.                 pygame.quit()
  33.                 exit()
  34.  
  35.             #SIDEWAYS CONTROL
  36.             elif event.type == pygame.KEYDOWN:
  37.  
  38.                 if event.key == pygame.K_RIGHT:
  39.                     CHARPOS[0] += 25
  40.                 elif event.key == pygame.K_LEFT:
  41.                     CHARPOS[0] -= 25
  42.  
  43.             #KEEPS FROM GOING OFF SCREEN
  44.             if CHARPOS[0] > WIDTH:
  45.                 CHARPOS[0] = 640
  46.             elif CHARPOS[0] <= 0:
  47.                 CHARPOS[0] = 0
  48.  
  49.         # No longer inside a "while True:", and indented properly :)
  50.         OBSTACLE[1] += 1
  51.  
  52.         SURFACE.fill(BLACK)
  53.  
  54.         #pygame.draw.circle(SURFACE, RED, (int(WIDTH / 2), (int(HEIGHT * 0.8))), 50)
  55.         pygame.draw.circle(SURFACE, RED, (CHARPOS), 50)
  56.  
  57.         DRAWRECT()
  58.  
  59.         CLOCK.tick(FPS)
  60.         pygame.display.flip()
  61.  
  62. except Exception as e:
  63.     print(e)
  64.     exit()
Advertisement
Add Comment
Please, Sign In to add comment