-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtetris.py
More file actions
67 lines (54 loc) · 1.57 KB
/
tetris.py
File metadata and controls
67 lines (54 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pygame
import random
# Configurações
pygame.init()
width, height = 300, 600
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()
pygame.display.set_caption("Tetris")
# Cores
BLACK = (0, 0, 0)
CYAN = (0, 255, 255)
YELLOW = (255, 255, 0)
GREEN = (0, 255, 0)
MAGENTA = (255, 0, 255)
RED = (255, 0, 0)
WHITE = (255, 255, 255)
# Peças do Tetris
tetrominos = [
[[1, 1, 1, 1], [0, 0, 0, 0], CYAN],
[[1, 1, 1, 0], [1, 0, 0, 0], YELLOW],
[[1, 1, 0, 0], [0, 1, 1, 0], GREEN],
[[1, 1, 1, 0], [0, 0, 1, 0], MAGENTA],
[[1, 1, 1, 0], [1, 0, 0, 0], RED],
[[1, 1, 1, 0], [0, 1, 0, 0], WHITE]
]
# Função para criar uma nova peça
def new_piece():
piece = random.choice(tetrominos)
color = piece[2]
return piece[:2], color
current_piece, current_color = new_piece()
x, y = width // 2, 0
# Função para desenhar uma peça na tela
def draw_piece(piece, color, x, y):
for row in range(2):
for col in range(4):
if piece[row][col]:
pygame.draw.rect(screen, color, pygame.Rect((x + col * 30, y + row * 30, 30, 30)))
# Loop principal do jogo
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Lógica do jogo aqui
# Limpe a tela
screen.fill(BLACK)
# Desenhe a peça atual
draw_piece(current_piece, current_color, x, y)
# Atualize a tela
pygame.display.flip()
# Controle a velocidade do jogo
clock.tick(30)
pygame.quit()