Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4.  
  5. display_width = 800
  6. display_height = 600
  7.  
  8. black = (0,0,0)
  9. white = (255,255,255)
  10. red = (255,0,0)
  11.  
  12. gameDisplay = pygame.display.set_mode((display_width,display_height))
  13. pygame.display.set_caption("A bit Racey")
  14.  
  15. carImg = pygame.image.load("racecar.png")
  16.  
  17.  
  18. def car(x,y):
  19. gameDisplay.blit(carImg,(x,y))
  20.  
  21.  
  22. x = (display_width * 0.45)
  23. y = (display_height *0.8)
  24.  
  25. x_change = 0
  26. y_change = 0
  27.  
  28.  
  29.  
  30. clock = pygame.time.Clock()
  31.  
  32. crashed = False
  33.  
  34.  
  35.  
  36. while not crashed:
  37.  
  38. for event in pygame.event.get():
  39.  
  40. if event.type == pygame.QUIT:
  41. crashed = True
  42.  
  43. if event.type == pygame.KEYDOWN:
  44. if event.key == pygame.K_LEFT:
  45. x_change = -10
  46.  
  47.  
  48. if event.key == pygame.K_RIGHT:
  49. x_change = 10
  50.  
  51. if event.type == pygame.KEYUP:
  52. if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
  53. x_change = 0
  54.  
  55.  
  56.  
  57. x += x_change
  58. if x == 830:
  59. x = -30
  60. if x == -30:
  61. x = 800
  62.  
  63. gameDisplay.fill(white)
  64. car(x,y)
  65.  
  66. pygame.display.update()
  67.  
  68. clock.tick(30)
  69.  
  70. pygame.quit()
  71. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement