/
display.py
61 lines (46 loc) · 1.54 KB
/
display.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
import pygame
from colors import *
width = 800
height = 800
assets = {}
rendered_objects = []
background = None
screen = None
def update():
global screen, background, rendered_objects, width, height
screen.fill(black)
if background:
screen.blit(background, (0, 0, width, height))
for r in rendered_objects:
r.render(screen)
pygame.display.flip()
def register(thing):
global rendered_objects
if thing not in rendered_objects:
rendered_objects.append(thing)
def remove(thing):
global rendered_objects
if thing in rendered_objects:
rendered_objects.remove(thing)
def init(w, h, cell_size, menu_width, playfield_w, playfield_h, background_line_width):
global screen, background, width, height
pygame.display.init()
width = w
height = h
screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN)
background = pygame.Surface((width, height))
background.fill(background_color)
for i in range(playfield_w):
pygame.draw.line(background, background_line_color, (cell_size * i + menu_width, 0),
(cell_size * i + menu_width, height), background_line_width)
for i in range(playfield_h):
pygame.draw.line(background, background_line_color, (menu_width, cell_size * i), (width, cell_size * i),
background_line_width)
def load(file):
global assets
if file in assets:
return assets[file]
else:
image = pygame.image.load(file)
assets[file] = image
return image