Advertisement
V3N0M_Z

Untitled

Jun 7th, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.05 KB | None | 0 0
  1. import pygame
  2. import sys
  3. from pygame.locals import *
  4. from math import *
  5. from random import *
  6. from time import sleep as wait
  7. from pygame import gfxdraw
  8. pygame.init()
  9. white = (52, 73, 94)
  10. FPS = 300
  11. fpsClock = pygame.time.Clock()
  12. screenSize = 0, 0
  13. scrx0, scry0 = screenSize
  14. scr = pygame.display.set_mode((scrx0,scry0), pygame.FULLSCREEN)
  15. scrx, scry = scr.get_size()
  16. fullScreen = True
  17. spd = 2.5
  18. size = 7
  19. sizeLimit = 200
  20. foodSize = 5
  21. foodIntensity = 150
  22. foodDots = set()
  23. generated = False
  24. pygame.display.set_caption("Pygame")
  25. scr.fill(white)
  26. mousepos = 0, 0
  27. prevpos = 0, 0
  28. orig = 0, 0
  29. sizePer = .25
  30. speedPer = .001
  31. bgImage = pygame.transform.scale(pygame.image.load('BG.PNG').convert(),
  32.                                  (scrx, scry))
  33. AI_limit = 10
  34. AI_generated = False
  35. AI_list = []
  36.  
  37. def genAI():
  38.     global AI_generated
  39.     if not AI_generated:
  40.         for n in range(AI_limit):
  41.             randSize = randint(7, int(size))
  42.             color = (randint(0, 255), randint(0, 255), randint(0, 255))
  43.             AI_list.insert(len(AI_list),
  44.                 (randSize, (randint(0, scrx), randint(0, scry)), color))
  45.         AI_generated = True
  46.     else:
  47.         if len(AI_list) < AI_limit:
  48.             for n in range(AI_limit-(len(AI_list))):
  49.                 randSize = randint(7, int(size))
  50.                 color = (randint(0, 255), randint(0, 255), randint(0, 255))
  51.                 AI_list.insert(len(AI_list), (randSize,
  52.                     (randint(0, scrx), randint(0, scry)), color))
  53.         for val in AI_list:
  54.             radius, position, color = val
  55.             x, y = position
  56.             pygame.gfxdraw.filled_circle(scr,
  57.                 x, y, radius, (color))
  58. def chk_AI(pos):
  59.     global size
  60.     x, y = pos
  61.     for n in AI_list:
  62.         radius, position, color = n
  63.         AI_posX, AI_posY = position
  64.         if hypot(AI_posX - x, AI_posY - y) <= (size-(radius/2)):
  65.             if not (size+radius) >= sizeLimit:
  66.                 size+=(radius/5)
  67.             AI_list.remove(n)
  68. def genCir():
  69.     global generated
  70.     for num in range(foodIntensity):
  71.         if generated == True:
  72.             for var in foodDots:
  73.                 dotsX, dotsY, r, g, b = var
  74.                 pygame.gfxdraw.filled_circle(scr,
  75.                            dotsX, dotsY, foodSize, (r, g, b))
  76.             return
  77.         posX = randint(0, scrx)
  78.         posY = randint(0, scry)
  79.         r, g, b = randint(150, 255), randint(150, 255), randint(150, 255)
  80.         pygame.gfxdraw.filled_circle(scr,
  81.                            posX, posY, foodSize, (r, g, b))
  82.         cirVar = posX, posY, r, g, b
  83.         foodDots.add(cirVar)
  84.     generated = True
  85. def ckDotColl(x):
  86.     global size, spd
  87.     x, y = x
  88.     z = []
  89.     for n in foodDots:
  90.         if hypot(n[0] - x, n[1] - y) <= (size+foodSize):
  91.             z.insert(len(z) ,n)
  92.     for n in z:
  93.         foodDots.remove(n)
  94.         if size < sizeLimit:
  95.             size+=sizePer
  96.         if not spd <= 1:
  97.             spd-=speedPer
  98. def dotCell():
  99.     if len(foodDots) < foodIntensity:
  100.         var = foodIntensity-(len(foodDots))
  101.         for n in range(var):
  102.             posX = randint(0, scrx)
  103.             posY = randint(0, scry)
  104.             r, g, b = randint(150, 255), randint(150, 255), randint(150, 255)
  105.             pygame.gfxdraw.filled_circle(scr,
  106.                 posX, posY, foodSize, (r, g, b))
  107.             cirVar = posX, posY, r, g, b
  108.             foodDots.add(cirVar)
  109. while True:
  110.     scr.fill(white)
  111.     scr.blit(bgImage, [0, 0])
  112.     for event in pygame.event.get():
  113.         if event.type == QUIT:
  114.             pygame.quit()
  115.             sys.exit()
  116.         elif event.type == pygame.KEYDOWN:
  117.             if event.key == pygame.K_ESCAPE:
  118.                 if fullScreen:
  119.                     fullScreen = False
  120.                     scr = pygame.display.set_mode((scrx, scry))
  121.                 else:
  122.                     fullScreen = True
  123.                     scr = pygame.display.set_mode((scrx0, scry0), pygame.FULLSCREEN)
  124.     mousepos = pygame.mouse.get_pos()
  125.     x, y = mousepos
  126.     x0, y0 = orig
  127.     x2, y2 = prevpos
  128.     dx = x - x2
  129.     dy = y - y2
  130.     distance = sqrt(dx*dx + dy*dy)
  131.     if distance == 0:
  132.         distance = .000000000000001
  133.     dx /= distance
  134.     dy /= distance
  135.     dx *= spd
  136.     dy *= spd
  137.     fx = x2+dx
  138.     fy = y2+dy
  139.     if int(ceil(fx)) < size:
  140.         fx = int(ceil(fx))+(size-int(ceil(fx)))
  141.     elif int(ceil(fx)) > scrx-size:
  142.         fx = (int(ceil(fx))-(int(ceil(fx))-scrx))-size
  143.     if int(ceil(fy)) < size:
  144.         fy = int(ceil(fy))+(size-int(ceil(fy)))
  145.     elif int(ceil(fy)) > scry-size:
  146.         fy = (int(ceil(fy))-(int(ceil(fy))-scry))-size
  147.     genCir();dotCell()
  148.     pygame.gfxdraw.filled_circle(scr, int(ceil(fx))-int((size/18)), int(ceil(fy))+int((size/18)), int(ceil(size)), (189, 195, 199))
  149.     pygame.gfxdraw.filled_circle(scr, int(ceil(fx)), int(ceil(fy)), int(ceil(size)), (236, 240, 241))
  150.     prevpos = fx, fy
  151.     ckDotColl((int(ceil(fx)), int(ceil(fy))))
  152.     orig = x, y
  153.     genAI()
  154.     chk_AI((int(fx), int(fy)))
  155.     pygame.display.update()
  156.     fpsClock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement