-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.py
63 lines (50 loc) · 1.83 KB
/
main.py
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
import pygame,sys
from game import Game
from colors import Colors
pygame.init()
title_font = pygame.font.Font(None, 40)
score_surface = title_font.render("Score", True, Colors.white)
next_surface = title_font.render("Next", True, Colors.white)
game_over_surface = title_font.render("GAME OVER", True, Colors.white)
score_rect = pygame.Rect(320, 55, 170, 60)
next_rect = pygame.Rect(320, 215, 170, 180)
screen = pygame.display.set_mode((500, 620))
pygame.display.set_caption("Python Tetris")
clock = pygame.time.Clock()
game = Game()
GAME_UPDATE = pygame.USEREVENT
pygame.time.set_timer(GAME_UPDATE, 200)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if game.game_over == True:
game.game_over = False
game.reset()
if event.key == pygame.K_LEFT and game.game_over == False:
game.move_left()
if event.key == pygame.K_RIGHT and game.game_over == False:
game.move_right()
if event.key == pygame.K_DOWN and game.game_over == False:
game.move_down()
game.update_score(0, 1)
if event.key == pygame.K_UP and game.game_over == False:
game.rotate()
if event.type == GAME_UPDATE and game.game_over == False:
game.move_down()
#Drawing
score_value_surface = title_font.render(str(game.score), True, Colors.white)
screen.fill(Colors.dark_blue)
screen.blit(score_surface, (365, 20, 50, 50))
screen.blit(next_surface, (375, 180, 50, 50))
if game.game_over == True:
screen.blit(game_over_surface, (320, 450, 50, 50))
pygame.draw.rect(screen, Colors.light_blue, score_rect, 0, 10)
screen.blit(score_value_surface, score_value_surface.get_rect(centerx = score_rect.centerx,
centery = score_rect.centery))
pygame.draw.rect(screen, Colors.light_blue, next_rect, 0, 10)
game.draw(screen)
pygame.display.update()
clock.tick(60)