Guest User

Untitled

a guest
Apr 12th, 2020
2,436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.04 KB | None | 0 0
  1. #!/usr/bin/python3.4
  2. # Setup Python ----------------------------------------------- #
  3. import pygame, sys, random
  4.  
  5. # Setup pygame/window ---------------------------------------- #
  6. mainClock = pygame.time.Clock()
  7. from pygame.locals import *
  8. pygame.init()
  9. pygame.display.set_caption('game base')
  10. screen = pygame.display.set_mode((500, 500),0,32)
  11.  
  12. TILE_SIZE = 20
  13.  
  14. # [loc, velocity, timer]
  15. particles = []
  16.  
  17. tile_map = {}
  18. for i in range(10):
  19.     tile_map[str(i + 4) + ';14'] = [i + 4, 14, (255, 0, 0)]
  20.  
  21. tile_map['15;10'] = [15, 10, (0, 0, 255)]
  22. tile_map['15;11'] = [15, 11, (0, 0, 255)]
  23. tile_map['15;12'] = [15, 12, (0, 0, 255)]
  24. tile_map['15;13'] = [15, 13, (0, 0, 255)]
  25.  
  26. tile_map['11;11'] = [11, 11, (0, 255, 255)]
  27. tile_map['11;12'] = [11, 12, (0, 255, 255)]
  28.  
  29. clicking = False
  30.  
  31. # Loop ------------------------------------------------------- #
  32. while True:
  33.    
  34.     # Background --------------------------------------------- #
  35.     screen.fill((0,0,0))
  36.     mx, my = pygame.mouse.get_pos()
  37.  
  38.     # Particles ---------------------------------------------- #
  39.     if clicking:
  40.         for i in range(30):
  41.             particles.append([[mx, my], [random.randint(0, 42) / 6 - 3.5, random.randint(0, 42) / 6 - 3.5], random.randint(4, 6)])
  42.  
  43.     for particle in particles:
  44.         particle[0][0] += particle[1][0]
  45.         loc_str = str(int(particle[0][0] / TILE_SIZE)) + ';' + str(int(particle[0][1] / TILE_SIZE))
  46.         if loc_str in tile_map:
  47.             particle[1][0] = -0.7 * particle[1][0]
  48.             particle[1][1] *= 0.95
  49.             particle[0][0] += particle[1][0] * 2
  50.         particle[0][1] += particle[1][1]
  51.         loc_str = str(int(particle[0][0] / TILE_SIZE)) + ';' + str(int(particle[0][1] / TILE_SIZE))
  52.         if loc_str in tile_map:
  53.             particle[1][1] = -0.7 * particle[1][1]
  54.             particle[1][0] *= 0.95
  55.             particle[0][1] += particle[1][1] * 2
  56.         particle[2] -= 0.035
  57.         particle[1][1] += 0.15
  58.         pygame.draw.circle(screen, (255, 255, 255), [int(particle[0][0]), int(particle[0][1])], int(particle[2]))
  59.         if particle[2] <= 0:
  60.             particles.remove(particle)
  61.  
  62.     # Render Tiles ------------------------------------------- #
  63.     for tile in tile_map:
  64.         pygame.draw.rect(screen, tile_map[tile][2], pygame.Rect(tile_map[tile][0] * TILE_SIZE, tile_map[tile][1] * TILE_SIZE, TILE_SIZE, TILE_SIZE))
  65.    
  66.     # Buttons ------------------------------------------------ #
  67.     for event in pygame.event.get():
  68.         if event.type == QUIT:
  69.             pygame.quit()
  70.             sys.exit()
  71.         if event.type == KEYDOWN:
  72.             if event.key == K_ESCAPE:
  73.                 pygame.quit()
  74.                 sys.exit()
  75.  
  76.         if event.type == MOUSEBUTTONDOWN:
  77.             if event.button == 1:
  78.                 clicking = True
  79.  
  80.         if event.type == MOUSEBUTTONUP:
  81.             if event.button == 1:
  82.                 clicking = False
  83.                
  84.     # Update ------------------------------------------------- #
  85.     pygame.display.update()
  86.     mainClock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment