Advertisement
Arcot

Pygame Basics

Sep 23rd, 2021
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame # importing the module
  2. WIDTH = 800
  3. HEIGHT = 600
  4. pygame.init() # initializing the module
  5. screen = pygame.display.set_mode((WIDTH, HEIGHT))  # making the window of size WIDTH and HEIGHT
  6.  
  7. run = True           # Game status -> game is running
  8. while run:           #-> while the game is running
  9.     pygame.time.delay(50)   # run this loop after every 50 milliseconds
  10.    
  11.     for event in pygame.event.get():  # for each event occuring in the window
  12.         if event.type == pygame.QUIT:  # checking if the close button was pressed
  13.             run = False     # update game status to stop (not running)
  14.            
  15.     pygame.display.update()  # update our window with all the changes that we have done
  16. pygame.quit() # close the window
  17.  
  18.  
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement