-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpygameRender.py
39 lines (32 loc) · 1.19 KB
/
pygameRender.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
import pygame as pg
class Display:
def __init__(self, config):
self.config = config
# game ground
self.config.pictures = []
for n in range(1, 8):
try:
self.config.pictures.append(
pg.transform.scale(pg.image.load("res/tetrisblock_%d.gif" % n),
(self.config.blocksize, self.config.blocksize)))
except FileNotFoundError as e:
print(e.errno)
# show screen
pg.init()
self.screen = pg.display.set_mode([self.config.width, self.config.height])
self.screen.fill((0, 0, 0))
def run(self):
for n, color in enumerate(self.config.grid): # from 0 to 199
if color > 0:
x = n % self.config.columns * self.config.distance
y = n // self.config.columns * self.config.distance
self.screen.blit(self.config.pictures[color], (x, y))
pg.display.flip()
def get_events(self):
return pg.event.get()
def get_pg_quit_event(self):
return pg.QUIT
def quit(self):
pg.quit()
# todo: find a way to quit in a proper way
exit(0)