Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import threading
- import time
- L =[["-----","--0--","--0--","--00-","-----"]]
- shapes = [L]
- class piece:
- def __init__(self):
- self.shape = random.choice(shapes)[0]
- self.cxcor = 50
- self.cycor = 50
- self.space = []
- pygame.init()
- running = True
- screen = pygame.display.set_mode((300,300))
- clock = pygame.time.Clock()
- #player = pygame.draw.rect(screen,(255, 0, 0),(20, 20, 20, 20))
- falling = piece()
- def piece_spawn():
- for i, row in enumerate(falling.shape):
- for j, column in enumerate(row):
- if column == "0":
- pygame.draw.rect(screen, (255,0,0), (50 + j*10, 50 + i*10, 10, 10))
- falling.space.append((50 + j*10, 50 + i*10))
- print(falling.space)
- pygame.display.update()
- def gravity():
- screen.fill((0,0,0))
- for element in stacked:
- pygame.draw.rect(screen, (255,0,0), (element[0], element[1], 10, 10))
- for s, a in enumerate(falling.space):
- pygame.draw.rect(screen, (255,0,0), (a[0], a[1]+10, 10, 10))
- falling.space.insert(s,[a[0], a[1] + 10])
- falling.space.pop(s+1)
- pygame.display.update()
- collided = True
- stacked = []
- def collision():
- global collided
- global stacked
- for element in falling.space:
- if element[1] == 250:
- collided = True
- for a in falling.space:
- stacked.append(a)
- falling.space = []
- def r_mov():
- for element in falling.space:
- element[0] += 10
- def l_mov():
- for element in falling.space:
- element[0] -= 10
- def loop1():
- global collided
- while True:
- if collided:
- collided = False
- piece_spawn()
- gravity()
- collision()
- time.sleep(0.1)
- p1 = threading.Thread(target=loop1)
- p1.start()
- while running:
- keys = pygame.key.get_pressed()
- if keys[pygame.K_a]:
- l_mov()
- if keys[pygame.K_d]:
- r_mov()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- time.sleep(0.05)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement