Advertisement
Ifrail

PygGame Base

Nov 5th, 2020 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import pygame
  2.  
  3. gameExit = False
  4. pygame.init()
  5. gameDisplay = pygame.display.set_mode((800, 600))
  6. pygame.display.set_caption("game")
  7.  
  8. car = pygame.image.load("car.png")
  9.  
  10. clock = pygame.time.Clock()
  11.  
  12. def process_keyboard(event):
  13.     global car_x_shift
  14.     if event.type == pygame.KEYDOWN:
  15.         if event.key == pygame.K_LEFT:
  16.             car_x_shift = -5
  17.         if event.key == pygame.K_RIGHT:
  18.             car_x_shift = 5
  19.     if event.type == pygame.KEYUP:
  20.         if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
  21.             car_x_shift = 0
  22.  
  23. def game_loop():
  24.     global gameExit
  25.     while not gameExit:
  26.         for event in pygame.event.get():
  27.             print(event)
  28.         process_keyboard(event)
  29.             if event.type == pygame.QUIT:
  30.                 gameExit = True
  31.                 quit()
  32.  
  33.         draw_object(car, car_x, car_y)
  34.         pygame.display.update()
  35.         clock.tick(30)
  36.  
  37.  
  38. game_loop()
  39. pygame.quit()
  40. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement