Last active
August 29, 2015 14:10
-
-
Save ogilviemt/288fd320eb3b0a9595de to your computer and use it in GitHub Desktop.
A collection of commonly declared variables for my .py scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pygame | |
| screen = pygame.display.set_mode([1024, 768]) | |
| height = pygame.display.Info().current_h | |
| width = pygame.display.Info().current_w | |
| pygame.display.set_caption('Window Caption') | |
| clock = pygame.time.Clock() | |
| #define some commonly used colours | |
| WHITE = (255, 255, 255) | |
| LIGHTGREY = (192, 192, 192) | |
| MEDIUMGREY = (128, 128, 128) | |
| DARKGREY = (64, 64, 64) | |
| BLACK = ( 0, 0, 0) | |
| RED = (255, 0, 0) | |
| GREEN = ( 0, 255, 0) | |
| BLUE = ( 0, 0, 255) | |
| YELLOW = (255, 255, 0) | |
| MAGENTA = (255, 0, 255) | |
| CYAN = ( 0, 255, 255) | |
| #define the dimensions of our universe | |
| screen = pygame.display.set_mode([1024, 768]) | |
| height = pygame.display.Info().current_h | |
| width = pygame.display.Info().current_w | |
| #set the caption of the window | |
| pygame.display.set_caption('Star Game') | |
| #create a var that will control frame rate | |
| clock = pygame.time.Clock() | |
| #initialize space for it to carry sounds | |
| pygame.mixer.init(44100, -16, 2, 4096) | |
| #create the window | |
| pygame.init() | |
| #make the mouse pointer invisible | |
| pygame.mouse.set_visible(0) | |
| app_is_alive = True | |
| while app_is_alive: | |
| for event in pygame.event.get(): | |
| if event.type == pygame.QUIT: | |
| print "Exiting... All hail the void!" | |
| app_is_alive = False | |
| if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: | |
| print "Exiting... All hail the void!" | |
| app_is_alive = False | |
| #my soul knows only darkness | |
| screen.fill(BLACK) | |
| #redraw everything we've asked pygame to draw | |
| pygame.display.flip() | |
| #set frames per second | |
| clock.tick(30) | |
| #quit gracefully | |
| pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment