RootOfTheNull

Python [pygame] 19 First World Editor

Mar 8th, 2014
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import pygame
  4. from colors import *
  5.  
  6. if ( __name__ == "__main__" ):
  7.  
  8.     pygame.init()
  9.  
  10.     size = width, height = 1200, 1000
  11.     window = pygame.display.set_mode( size )
  12.  
  13.     clock = pygame.time.Clock()
  14.     fps = 60
  15.  
  16.     window.fill( white )
  17.     pygame.display.update(  )
  18.  
  19.     to_draw = [  ]
  20.  
  21.     draw_start_box = False
  22.  
  23.     running = True
  24.     while ( running ):
  25.         for event in pygame.event.get():
  26.             if ( event.type == pygame.QUIT ) or ( event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE ):
  27.                 running = False
  28.  
  29.             if ( event.type == pygame.MOUSEMOTION ):
  30.                 mouse_pos = mouse_x, mouse_y = pygame.mouse.get_pos()
  31.  
  32.             if ( event.type == pygame.MOUSEBUTTONDOWN ):
  33.                 pos = mouse_pos
  34.                 draw_start_box = True
  35.             if ( event.type == pygame.MOUSEBUTTONUP ):
  36.                 final_pos = mouse_pos
  37.                 draw_start_box = False
  38.  
  39.                 to_draw += [ pygame.Rect( pos, ( final_pos[0] - pos[0], final_pos[1] - pos[1] ) ) ]
  40.  
  41.  
  42.             if ( event.type == pygame.KEYDOWN ):
  43.                 if ( event.key == pygame.K_RETURN ):
  44.                     for platform in to_draw:
  45.                         print "[" + str(platform).split("(")[1].split(")")[0] + ", black ],"
  46.  
  47.                 if ( event.key == pygame.K_BACKSPACE ):
  48.                     to_draw.pop()
  49.  
  50.  
  51.         window.fill( white )
  52.  
  53.         if ( draw_start_box ):
  54.             pygame.draw.rect( window, red, pygame.Rect( pos, ( mouse_pos[0] - pos[0], mouse_pos[1] -pos[1] ) ) )
  55.  
  56.         for item in to_draw:
  57.             pygame.draw.rect( window, black, item )
  58.  
  59.  
  60.         pygame.display.update()
  61.  
  62.         clock.tick( fps )
  63.  
  64.  
  65.  
  66.     pygame.quit()
RAW Paste Data