Advertisement
Guest User

pygame_event.py

a guest
Feb 22nd, 2011
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import math
  2. import pygame, sys
  3. from pygame.locals import *
  4. pygame.init()
  5. (windows_width, windows_height, windows_title) = (600, 400, "PyGame Event")
  6. screen = pygame.display.set_mode((windows_width,windows_height),0,32)
  7. pygame.display.set_caption(windows_title)
  8. windows_bgcolor = (255,255,255)
  9.  
  10. circle_pos = (0,0)
  11. circle_color = (255, 0, 0)
  12. circle_radius = 10
  13.  
  14. #pygame.event.set_blocked([MOUSEBUTTONDOWN, KEYDOWN])
  15. block_flag = False
  16.  
  17. mainLoop = True
  18. #initial data here
  19. while mainLoop:
  20.     for event in pygame.event.get():
  21.         if event.type == MOUSEBUTTONDOWN:
  22.             if event.button == 1:
  23.                 circle_pos = event.pos
  24.         if event.type == KEYDOWN:
  25.             if event.key == K_SPACE:
  26.                 block_flag = not block_flag
  27.                 print 'MOUSEBUTTONDOWN is block: ', pygame.event.get_blocked(MOUSEBUTTONDOWN)
  28.                 if block_flag:
  29.                     pygame.event.set_blocked(MOUSEBUTTONDOWN)
  30.                 else:
  31.                     pygame.event.set_allowed(MOUSEBUTTONDOWN)
  32.             if event.key == K_ESCAPE:
  33.                 mainLoop = False            
  34.         if event.type == QUIT:
  35.             mainLoop = False
  36.     screen.fill(windows_bgcolor)
  37.     #create frame here
  38.     pygame.draw.circle(screen, circle_color, circle_pos, circle_radius);
  39.     pygame.display.update()
  40. pygame.quit()
  41. #destroy data here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement