-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (61 loc) · 1.94 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import numpy
import pygame
import random
import tetriminos
import game as game_class
import game_constants as gc
def main():
pygame.init()
win = pygame.display.set_mode((gc.WIN_WIDTH, gc.WIN_HEIGHT))
pygame.display.set_caption('Tetris')
game_loop(win)
def game_loop(win):
game = game_class.Game()
clock = pygame.time.Clock()
tiles = [
tetriminos.I_Tetrimino(5, 0),
tetriminos.O_Tetrimino(5, 0),
tetriminos.T_Tetrimino(5, 0),
tetriminos.S_Tetrimino(5, 0),
tetriminos.Z_Tetrimino(5, 0),
tetriminos.J_Tetrimino(5, 0),
tetriminos.L_Tetrimino(5, 0)
]
bg_img = game.draw_bg(win)
static_array = game.get_static_game_array()
tile = random.choice(tiles)
spawn_new_tile = False
run = True
while run:
clock.tick(30)
if spawn_new_tile:
tile = random.choice(tiles)
spawn_new_tile = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
pygame.quit()
quit()
if event.key == pygame.K_SPACE:
tile.rotate(static_array)
if event.key == pygame.K_LEFT:
tile.move_x(static_array, -1)
if event.key == pygame.K_RIGHT:
tile.move_x(static_array, 1)
update = tile.move_y(static_array)
if update is not None:
game.update_static_game_array(update)
spawn_new_tile = True
game.print_static_game_array()
# tile.print()
# game.print_static_game_array()
draw_ingame_window(win, bg_img, tile)
def draw_ingame_window(win, bg_img, tile):
win.blit(bg_img, (0, 0))
tile.draw(win)
pygame.display.update()
if __name__ == '__main__':
main()