Advertisement
Ferunelli_

Heart

Mar 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. import os
  2. from math import fabs
  3. import pygame
  4. import random
  5. from pygame.locals import *
  6.  
  7. pygame.init()
  8. pygame.font.init()
  9.  
  10. cell = []
  11. def randomize(m, n):
  12.     k  = random.randint(m, n)
  13.     if (k not in cell) & (k != None):
  14.         cell.append(k)
  15.         return k
  16.     else:
  17.         randomize(m, n)
  18. for i in range(4):
  19.     randomize(0,3)
  20.     randomize(4,7)
  21.     randomize(8,11)
  22.     randomize(12,15)
  23.  
  24.  
  25. WHITE = [255, 255, 255]
  26.  
  27. screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
  28. pygame.display.set_caption("Hello my darling. This is only for you")
  29. gameIcon = pygame.image.load('Heart.png')
  30. pygame.display.set_icon(gameIcon)
  31.  
  32. heart = pygame.image.load(os.path.join("Heart.png"))
  33. heart.convert()
  34. hearts_positioning = []
  35.  
  36.  
  37. for i in range(12):
  38.     x = random.randrange((cell[i]%4)*400, ((cell[i]%4)+1)*400)
  39.     y = random.randrange(((cell[i]//4)*(-300)-300) , (cell[i]//4)*(-300))
  40.     s = random.randint(2,4)
  41.     if s > 2:
  42.         z = random.randint(-1,1)
  43.         hearts_positioning.append([x, y, s, z])
  44.     else:
  45.         hearts_positioning.append([x, y, s, 0])
  46.  
  47. clock = pygame.time.Clock()
  48. done = False
  49. while not done:
  50.     for event in pygame.event.get():
  51.         if event.type == pygame.locals.KEYDOWN:
  52.             if (event.key == K_ESCAPE):
  53.                 done = True
  54.     screen.fill(WHITE)
  55.  
  56.     for i in range(len(hearts_positioning)):
  57.  
  58.         screen.blit(heart, (hearts_positioning[i][0], hearts_positioning[i][1]))
  59.         hearts_positioning[i][1] += hearts_positioning[i][2]
  60.         hearts_positioning[i][0] += hearts_positioning[i][3]
  61.  
  62.         if hearts_positioning[i][1] > 1080:
  63.             y = random.randrange(((cell[i]//4)*(-300)-300) , (cell[i]//4)*(-300))-300
  64.             hearts_positioning[i][1] = y
  65.             x = random.randrange((cell[i]%4)*400, ((cell[i]%4)+1)*400)
  66.             hearts_positioning[i][0] = x
  67.             s = random.randint(2, 4)
  68.             hearts_positioning[i][2] = s
  69.             if s > 2:
  70.                 z = random.randint(-1, 1)
  71.                 hearts_positioning[i][3]= z
  72.             else:
  73.                 hearts_positioning[i][3]= 0
  74.  
  75.     pygame.display.flip()
  76.     clock.tick(60)
  77.  
  78. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement