Advertisement
zicaentu

Template with functions

Nov 9th, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. """
  2. Pygame base template for opening a window, done with functions
  3.  
  4.  
  5. """
  6. import pygame
  7.  
  8.  
  9. # Define some colors as global constants
  10. BLACK = (0x00, 0x00, 0x00)
  11. WHITE = (0xff, 0xff, 0xff)
  12. GREEN = (0x00, 0xff, 0x00)
  13. RED =   (0xff, 0x00, 0x00)
  14.  
  15.  
  16. def main():
  17.     """ Main function for the game. """
  18.     pygame.init()
  19.  
  20.     # Set the width and height of the screen [width,height]
  21.     size = [800, 600]
  22.     screen = pygame.display.set_mode(size)
  23.  
  24.     pygame.display.set_caption("My Game")
  25.  
  26.     running = True
  27.  
  28.     clock = pygame.time.Clock()
  29.  
  30.     # -------- Main Program Loop -----------
  31.     while running:
  32.         # Event processing
  33.         for event in pygame.event.get():
  34.             if event.type == pygame.QUIT:
  35.                 running = False
  36.         # Game logic
  37.  
  38.         # Code to draw
  39.         screen.fill(WHITE)
  40.  
  41.         pygame.display.flip()
  42.         clock.tick(60)
  43.     pygame.quit()
  44.  
  45. if __name__ == "__main__":
  46.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement