SHARE
TWEET

Hakology - pygame tutorial - part 1

a guest Jun 27th, 2013 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # more at youtube.com/hakology or hakology.wordpress.com
  2. import pygame
  3. from pygame.locals import *
  4.  
  5. wWIDTH = 640
  6. wHEIGHT = 480
  7.  
  8. def main():
  9.     r = 1
  10.     while(1):  # do for a while (game loop)
  11.         for event in pygame.event.get():  # handle events
  12.             if event.type == QUIT:  # ctrl+c
  13.                 r = 0  # return 0 = (game is over)
  14.             elif event.type == KEYDOWN:  # down arrow
  15.                 if event.key == K_ESCAPE:
  16.                     r = 0  # return 0 = (game is over)
  17.                 if event.key == K_q:  # q key pressed
  18.                     r = 0
  19.         GSURF.fill((0, 0, 0))
  20.         if r != 1:
  21.             break
  22.     return r
  23.  
  24. if __name__ == "__main__":  # main function call
  25.     r = 1  # set variable for return value
  26.     pygame.init()  # initialise python pygame
  27.     GCLOCK = pygame.time.Clock()  # set game clock
  28.     GSURF = pygame.display.set_mode((wWIDTH, wHEIGHT))  # main game surface
  29.     while r != 0:  # quit if return not equal to 0 (0 = game exit, 1 = restart main loop)
  30.         r = main()  # get return value from main loop (1 == OK ... 0 == exit)
RAW Paste Data
Top