Advertisement
thenewboston

[source code] Pygame (Python Game Development) Tutorial 87

Nov 15th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 KB | None | 0 0
  1. import pygame
  2. import time
  3. import random
  4.  
  5. pygame.init()
  6.  
  7. display_width = 800
  8. display_height = 600
  9.  
  10. gameDisplay = pygame.display.set_mode((display_width,display_height))
  11.  
  12. pygame.display.set_caption('3d')
  13.  
  14. white = (255,255,255)
  15. black = (0,0,0)
  16.  
  17. red = (200,0,0)
  18. light_red = (255,0,0)
  19.  
  20. yellow = (200,200,0)
  21. light_yellow = (255,255,0)
  22.  
  23. green = (34,177,76)
  24. light_green = (0,255,0)
  25.  
  26. clock = pygame.time.Clock()
  27.  
  28. smallfont = pygame.font.SysFont("comicsansms", 25)
  29. medfont = pygame.font.SysFont("comicsansms", 50)
  30. largefont = pygame.font.SysFont("comicsansms", 85)
  31.  
  32. FPS = 30
  33.  
  34.  
  35. def square(startPoint, fullSize):
  36.     node_1 = [startPoint[0], startPoint[1]]
  37.     node_2 = [startPoint[0]+fullSize, startPoint[1]]
  38.     node_3 = [startPoint[0], startPoint[1]+fullSize]
  39.     node_4 = [startPoint[0]+fullSize, startPoint[1]+fullSize]
  40.  
  41.     # top line #
  42.     pygame.draw.line(gameDisplay, white, (node_1),(node_2))
  43.     # bottom line #
  44.     pygame.draw.line(gameDisplay, white, (node_3),(node_4))
  45.     # left line #
  46.     pygame.draw.line(gameDisplay, white, (node_1),(node_3))
  47.     # right line #
  48.     pygame.draw.line(gameDisplay, white, (node_2),(node_4))
  49.  
  50.  
  51.     pygame.draw.circle(gameDisplay, light_green, node_1, 5)
  52.     pygame.draw.circle(gameDisplay, light_green, node_2, 5)
  53.     pygame.draw.circle(gameDisplay, light_green, node_3, 5)
  54.     pygame.draw.circle(gameDisplay, light_green, node_4, 5)
  55.  
  56.  
  57.    
  58.    
  59.  
  60.  
  61. def gameLoop():
  62.  
  63.     location = [300,200]
  64.     size = 200
  65.  
  66.     current_move = 0
  67.  
  68.     z_move = 0
  69.     z_location = 1
  70.  
  71.     while True:
  72.        
  73.         for event in pygame.event.get():
  74.  
  75.             if event.type == pygame.QUIT:
  76.                 pygame.quit()
  77.                 quit()
  78.  
  79.             if event.type == pygame.KEYDOWN:
  80.                 if event.key == pygame.K_LEFT:
  81.                     current_move = -5
  82.                    
  83.                 elif event.key == pygame.K_RIGHT:
  84.                     current_move = 5
  85.                 elif event.key == pygame.K_UP:
  86.                     z_move = -5
  87.                     current_move = -1
  88.                 elif event.key == pygame.K_DOWN:
  89.                     z_move = 5
  90.                     current_move = 1
  91.                    
  92.  
  93.             elif event.type == pygame.KEYUP:
  94.                 if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
  95.                     current_move = 0
  96.  
  97.                 if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
  98.                     z_move = 0
  99.                     current_move = 0
  100.  
  101.         gameDisplay.fill(black)
  102.  
  103.         if z_location > 200:
  104.             z_move = 0
  105.  
  106.         z_location += z_move
  107.  
  108.         current_size = int(size / (z_location*0.1))
  109.  
  110.         location[0] += current_move
  111.  
  112.         square(location, current_size)
  113.         pygame.display.update()
  114.        
  115.         clock.tick(FPS)
  116.  
  117.     pygame.quit()
  118.     quit()
  119.  
  120. gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement