-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTetris.py
54 lines (51 loc) · 1.62 KB
/
Tetris.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
# v0.0.2
# author Konrad Schultz
import pygame
import TetrisPieces
from pygame.locals import *
def main():
# screen surface
pygame.init()
size = 920, 640
screen = pygame.display.set_mode(size)
# fps counter/speed regulator
clock = pygame.time.Clock()
# music
pygame.mixer.music.load("sound/theme2.mp3")
pygame.mixer.music.play(10)
pygame.mixer.music.set_volume(0.1)
# board
board = pygame.image.load("img/Board.png")
board_rect = board.get_rect()
t_game = TetrisPieces.TetrisApp()
pygame.key.set_repeat(200, 50)
loop_counter = 0
# control loop
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
elif event.type == KEYDOWN:
if event.key == K_LEFT:
t_game.active.move_left(t_game)
if event.key == K_RIGHT:
t_game.active.move_right(t_game)
if event.key == K_DOWN:
t_game.active.move_down(t_game)
if event.key == K_SPACE:
t_game.active.drop_down(t_game)
if event.key == K_UP:
t_game.active.rotate_cw() # rotate cw
if event.key == K_v:
t_game.active.rotate_ccw()
if loop_counter % 7 == 0:
t_game.active.move_down(t_game)
loop_counter %= 7
screen.blit(board, board_rect)
t_game.active.draw(screen)
t_game.passive.draw(screen)
pygame.display.flip()
clock.tick(60)
loop_counter += 1
if __name__ == "__main__":
main()