-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.py
74 lines (61 loc) · 2.68 KB
/
render.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
#!/usr/bin/env python
import pygame
from pygame.locals import color
import resources
import basic as theme
class Render(object):
def __init__(self, game):
self.__game = game
scr_size = (self.__game.size[0] * theme.BRICK_SIZE + 4,
self.__game.size[1] * theme.BRICK_SIZE + 4)
self.__scr = pygame.Surface(scr_size)
self.__scr.fill(color.THECOLORS['white'])
board_size = (self.__game.size[0] * theme.BRICK_SIZE,
self.__game.size[1] * theme.BRICK_SIZE)
self.__board = pygame.Surface(board_size)
self.__board.fill(color.THECOLORS['black'])
self.__next = pygame.Surface((theme.BRICK_SIZE * 4,
theme.BRICK_SIZE * 4))
self.__next.fill(color.THECOLORS['black'])
@property
def surface(self):
self.__scr.blit(self.__board, (2, 2))
return self.__scr
@property
def next(self):
return self.__next
def score(self, score):
return resources.FONT.render('%04d' % score, 1,
(255, 255, 255, 255),
(0, 0, 0, 255))
def level(self, level):
return resources.FONT.render('%02d' % level, 1,
(255, 255, 255, 255),
(0, 0, 0, 255))
def update(self):
for y in range(len(self.__game.board)):
for x in range(len(self.__game.board[y])):
brick = theme.BRICKS.get(self.__game.board[y][x], None)
if not brick:
continue
self.__board.blit(brick, (x * theme.BRICK_SIZE,
y * theme.BRICK_SIZE))
self.__next.fill(color.THECOLORS['black'])
for y in range(len(self.__game.next)):
for x in range(len(self.__game.next[y])):
brick = theme.BRICKS.get(self.__game.next[y][x], None)
if not brick:
continue
self.__next.blit(brick, (x * theme.BRICK_SIZE,
y * theme.BRICK_SIZE))
for y in range(len(self.__game.player)):
for x in range(len(self.__game.player[y])):
if not self.__game.player[y][x]:
continue
brick = theme.BRICKS.get(self.__game.player[y][x], None)
if not brick:
continue
self.__board.blit(brick,
((x + self.__game.player_position[0]) * theme.BRICK_SIZE,
(y + self.__game.player_position[1]) * theme.BRICK_SIZE))
return self.surface