Advertisement
Guest User

s

a guest
Nov 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import random, pygame, sys
  2. from pygame.locals import *
  3.  
  4. FPS = 10
  5. WINDOWWIDTH = 1600
  6. WINDOWHEIGHT = 900
  7. CELLSIZE = 20
  8. assert WINDOWWIDTH % CELLSIZE == 0, "Window width must be a multiple of cell size."
  9. assert WINDOWHEIGHT % CELLSIZE == 0, "Window height must be a multiple of cell size."
  10. CELLWIDTH = int(WINDOWWIDTH / CELLSIZE)
  11. CELLHEIGHT = int(WINDOWHEIGHT / CELLSIZE)
  12.  
  13. # R G B
  14. WHITE = (255, 255, 255)
  15. BLACK = ( 0, 0, 0)
  16. RED = (255, 0, 0)
  17. GREEN = ( 0, 255, 0)
  18. DARKGREEN = ( 0, 155, 0)
  19. DARKGRAY = ( 40, 40, 40)
  20. BGCOLOR = BLACK
  21.  
  22. UP = 'up'
  23. DOWN = 'down'
  24. LEFT = 'left'
  25. RIGHT = 'right'
  26.  
  27. #Directions and controls (fix still broken)
  28. for event in pygame.event.get(): # event handling loop
  29. if event.type == QUIT:
  30. terminate()
  31. elif event.type == KEYDOWN:
  32. if (event.key == K_LEFT or event.key == K_a) and direction != RIGHT:
  33. direction = LEFT
  34. elif (event.key == K_RIGHT or event.key == K_d) and direction != LEFT:
  35. direction = RIGHT
  36. elif (event.key == K_UP or event.key == K_w) and direction != DOWN:
  37. direction = UP
  38. elif (event.key == K_DOWN or event.key == K_s) and direction != UP:
  39. direction = DOWN
  40. elif event.key == K_ESCAPE:
  41. terminate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement