-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (38 loc) · 1.3 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
from settings import *
from tetris import Tetris
import sys
class App:
def __init__(self):
pg.init()
pg.display.set_caption('TETRIS HEART')
self.screen =pg.display.set_mode(FIELD_RES)
self.clock = pg.time.Clock()
self.set_timer()
self.tetris = Tetris(self)
def set_timer(self):
self.user_event = pg.USEREVENT + 0
self.anim_trigger = False
pg.time.set_timer(self.user_event, ANIM_TIME_INTERVAL)
def update(self):
self.tetris.update()
self.clock.tick(FPS)
def draw(self):
self.screen.fill(color=FIELD_COLOR)
self.tetris.draw()
pg.display.flip()
def check_events(self):
self.anim_trigger= False
for event in pg.event.get():
if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
pg.quit()
sys.exit()
elif event.type == self.user_event:
self.anim_trigger = True
def run(self):
while True:
self.check_events()
self.update()
self.draw()
if __name__ == '__main__':
app = App()
app.run() #run app