-
Notifications
You must be signed in to change notification settings - Fork 1
/
Update main.py
76 lines (62 loc) · 2.61 KB
/
Update 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
64
65
66
67
68
69
70
71
72
73
74
75
76
import pygame
import sys
from game import Game
from colors import Colors
pygame.init()
#title
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.red)
#rectangle score screen
score_rect = pygame.Rect(320, 55, 170, 60)
next_rect = pygame.Rect(320, 215, 170, 180)
#create game window
screen = pygame.display.set_mode((500,620))
pygame.display.set_caption("Tetris Game 2.0")
#Importing new background
background_img = pygame.image.load('background2.jpg')
clock = pygame.time.Clock()
#create game object
game = Game()
#create event that is triggered every time the game needs to be updated (200 milliseconds)
GAME_UPDATE = pygame.USEREVENT
pygame.time.set_timer(GAME_UPDATE, 200)
#adding game loop for consistency in all players
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#to detect block movement using keyboard,call game.py
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.orange)
screen.fill(Colors.black)
#Adding Background image
screen.blit(background_img, (0, 0))
#Adding Scoreboard backdrop
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)