Advertisement
Guest User

Game.py

a guest
Nov 30th, 2014
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. import pygame
  2.  
  3. #Init Test
  4. init_test = pygame.init()
  5.  
  6. #Colors
  7. white = (255, 255, 255)
  8. white_smoke = (245, 245, 245)
  9. light_gray = (211, 211, 211)
  10. gray = (128, 128, 128)
  11. dark_gray = (169, 169, 169)
  12. black = (0, 0, 0)
  13.  
  14. red = (255, 0, 0)
  15. fire_break = (178, 34, 34)
  16.  
  17. royal_blue = (65, 105, 225)
  18. navy = (0, 0, 128)
  19.  
  20. #Display
  21. display_width = 800
  22. display_height = 600
  23. game_display = pygame.display.set_mode((display_width, display_height))
  24.  
  25. center_x = display_width / 2
  26. center_y = display_height / 2
  27.  
  28. game_display.fill(white)
  29. pygame.display.update()
  30.  
  31. #Name
  32. pygame.display.set_caption('A bit racey.')
  33.  
  34. #FPS
  35. clock = pygame.time.Clock()
  36. fps = 30
  37.  
  38. #Images
  39. car_image = pygame.image.load('car.png')
  40.  
  41. #Car
  42. car_x = (display_width / 2) - (car_image.get_rect().size[0] / 2)
  43. car_y = display_height - (car_image.get_rect().size[1] * 2)
  44. car_x_change = 0
  45.  
  46. def car(car_x, car_y):
  47.     game_display.blit(car_image, (car_x, car_y))
  48.  
  49. #Game
  50. def gameLoop():
  51.  
  52.     #Game State
  53.     game_exit = False
  54.     game_over = False
  55.  
  56.     #Game Loop
  57.     while not game_exit:
  58.  
  59.         #Game Over
  60.         while game_over == True:
  61.             game_display.fill(white)
  62.             pygame.display.update()
  63.  
  64.             for event in pygame.event.get():
  65.                 if event.type == pygame.QUIT:
  66.                         game_exit = True
  67.                         game_over = False
  68.  
  69.         #Events
  70.         for event in pygame.event.get():
  71.             if event.type == pygame.QUIT:
  72.                 game_exit = True
  73.                
  74.             if event.type == pygame.KEYDOWN:
  75.                 if event.key == pygame.K_LEFT:
  76.                     car_x_change = -5
  77.  
  78.                 elif event.key == pygame.K_RIGHT:
  79.                     car_x_change = 5
  80.  
  81.         #Game funtionality
  82.         car(car_x, car_y)
  83.  
  84.         #Update the display
  85.         pygame.display.update()
  86.  
  87.         #FPS
  88.         clock.tick(fps)
  89.  
  90.     #Quit Game
  91.     pygame.quit()
  92.     quit()
  93.  
  94. gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement