RootOfTheNull

Python [pygame] 19 First World Editor

Jan 17th, 2016
225
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.     draw_start_box = False
  21.  
  22.     running = True
  23.     while ( running ):
  24.         for event in pygame.event.get():
  25.             if ( event.type == pygame.QUIT ) or ( event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE ):
  26.                 running = False
  27.  
  28.             if ( event.type == pygame.MOUSEMOTION ):
  29.                 mouse_pos = mouse_x, mouse_y = pygame.mouse.get_pos()
  30.  
  31.             if ( event.type == pygame.MOUSEBUTTONDOWN ):
  32.                 pos = mouse_pos
  33.                 draw_start_box = True
  34.  
  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.             if ( event.type == pygame.KEYDOWN ):
  42.                 if ( event.key == pygame.K_RETURN ):
  43.                     for platform in to_draw:
  44.                         print "[" + str( platform ).split("(")[1].split(")")[0] + "]"
  45.  
  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.         clock.tick(fps)
  62.  
  63.     pygame.quit()
RAW Paste Data