Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import pygame
  2. import random
  3. import threading
  4. import time
  5.  
  6. L =[["-----","--0--","--0--","--00-","-----"]]
  7. shapes = [L]
  8.  
  9. class piece:
  10. def __init__(self):
  11. self.shape = random.choice(shapes)[0]
  12. self.cxcor = 50
  13. self.cycor = 50
  14. self.space = []
  15.  
  16. pygame.init()
  17. running = True
  18. screen = pygame.display.set_mode((300,300))
  19. clock = pygame.time.Clock()
  20.  
  21. #player = pygame.draw.rect(screen,(255, 0, 0),(20, 20, 20, 20))
  22.  
  23. falling = piece()
  24.  
  25.  
  26. def piece_spawn():
  27. for i, row in enumerate(falling.shape):
  28. for j, column in enumerate(row):
  29. if column == "0":
  30. pygame.draw.rect(screen, (255,0,0), (50 + j*10, 50 + i*10, 10, 10))
  31. falling.space.append((50 + j*10, 50 + i*10))
  32.  
  33. print(falling.space)
  34. pygame.display.update()
  35.  
  36. def gravity():
  37. screen.fill((0,0,0))
  38. for element in stacked:
  39. pygame.draw.rect(screen, (255,0,0), (element[0], element[1], 10, 10))
  40.  
  41. for s, a in enumerate(falling.space):
  42. pygame.draw.rect(screen, (255,0,0), (a[0], a[1]+10, 10, 10))
  43. falling.space.insert(s,[a[0], a[1] + 10])
  44. falling.space.pop(s+1)
  45.  
  46. pygame.display.update()
  47.  
  48. collided = True
  49.  
  50. stacked = []
  51.  
  52. def collision():
  53. global collided
  54. global stacked
  55. for element in falling.space:
  56. if element[1] == 250:
  57. collided = True
  58. for a in falling.space:
  59. stacked.append(a)
  60. falling.space = []
  61.  
  62. def r_mov():
  63. for element in falling.space:
  64. element[0] += 10
  65. def l_mov():
  66. for element in falling.space:
  67. element[0] -= 10
  68.  
  69. def loop1():
  70. global collided
  71. while True:
  72. if collided:
  73. collided = False
  74. piece_spawn()
  75. gravity()
  76. collision()
  77. time.sleep(0.1)
  78. p1 = threading.Thread(target=loop1)
  79. p1.start()
  80.  
  81. while running:
  82.  
  83. keys = pygame.key.get_pressed()
  84. if keys[pygame.K_a]:
  85. l_mov()
  86. if keys[pygame.K_d]:
  87. r_mov()
  88.  
  89. for event in pygame.event.get():
  90. if event.type == pygame.QUIT:
  91. running = False
  92.  
  93. time.sleep(0.05)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement