fork download
  1. pygame.init()
  2.  
  3. display_width = 800
  4. display_height = 600
  5.  
  6. black = (0,0,0)
  7. white = (255,255,255)
  8. red = (255,0,0)
  9. green = (0,255,0)
  10.  
  11. car_width = 73
  12.  
  13. gameDisplay = pygame.display.set_mode((display_width,display_height))
  14. pygame.display.set_caption('drivin meh truck-by me')
  15. clock = pygame.time.Clock()
  16.  
  17. carImg = pygame.image.load('truck.png')
  18.  
  19. def things(thingx, thingy, thingw, thingh, color):
  20. pygame.draw.rect(gameDisplay, color,[thingx, thingy, thingw, thingh]) #this is were i get the error
  21.  
  22. def car(x,y):
  23. gameDisplay.blit(carImg,(x,y))
  24.  
  25. def text_objects(text, font):
  26. textSurface = font.render(text, True, green)
  27. return textSurface, textSurface.get_rect()
  28.  
  29. def message_display(text):
  30. LargeText = pygame.font.Font('freesansbold.ttf',80)
  31. TextSurf, TextRect = text_objects(text,LargeText)
  32. TextRect.center = ((display_width/2),(display_height/2))
  33. gameDisplay.blit(TextSurf, TextRect)
  34.  
  35. pygame.display.update()
  36.  
  37. time.sleep(2)
  38.  
  39. game_loop()
  40.  
  41. def crash():
  42. message_display('you done goofed')
  43.  
  44. def game_loop():
  45.  
  46. x = (display_width * 0.45)
  47. y = (display_height * 0.8)
  48.  
  49. x_change = 0
  50.  
  51. thing_startx = random.randrange,(0, display_width)
  52. thing_starty = -600
  53. thing_speed = 7
  54. thing_width = 100
  55. thing_height = 100
  56.  
  57. gameExit = False
  58.  
  59. while not gameExit:
  60.  
  61. for event in pygame.event.get():
  62. if event.type == pygame.QUIT:
  63. pygame.quit()
  64. quit()
  65.  
  66. if event.type == pygame.KEYDOWN:
  67. if event.key == pygame.K_LEFT:
  68. x_change = -5
  69. elif event.key == pygame.K_RIGHT:
  70. x_change = 5
  71.  
  72. if event.type == pygame.KEYUP:
  73. if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
  74. x_change = 0
  75.  
  76. x += x_change
  77.  
  78. gameDisplay.fill(white)
  79.  
  80.  
  81. things(thing_startx, thing_starty, thing_width, thing_height, red)
  82. thing_starty += thing_speed
  83. car(x,y)
  84.  
  85. if x > display_width - car_width or x < 0:
  86. crash()
  87.  
  88.  
  89. pygame.display.update()
  90. clock.tick(60)
  91.  
  92. game_loop()
  93.  
  94. pygame.quit()
  95. quit()# your code goes here
Runtime error #stdin #stdout #stderr 0.02s 9984KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
NameError: name 'pygame' is not defined