def __init__(self, width=640, height=400, fps=30, filename = "level1.txt", tilew = 20, tileh = 20):
"""Initialize pygame, window, background, font,...
default arguments
"""
pygame.init()
pygame.display.set_caption("--- MAP-VIEWER ---")
PygView.width = width # make global readable
PygView.height = height
self.filename = filename
self.tilew = tilew
self.tileh = tileh
self.lines = []
try:
lines = 0
chars = 0
with open(self.filename) as myfile:
for line in myfile:
self.lines.append(line[:-1])
lines += 1
chars = len(line) - 1
except:
print("-- fileReadingError --")
print(lines, chars)
PygView.width = chars * self.tilew
PygView.height = lines * self.tileh
self.colourdict = {3:(1, 0, 122),
4:(93, 92, 244),
5:(145, 144, 245),
6:(246, 252, 84),
7:(226, 144, 36),
8:(127, 127, 127)}
self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
self.background = pygame.Surface(self.screen.get_size()).convert()
self.background.fill((255,255,255)) # fill background white
for line in range(lines):
for char in range(chars):
pygame.draw.rect(self.background, self.colourdict[int(self.lines[line][char])],
(self.tilew * char, self.tileh * line, tilew, tileh))
#self.clock = pygame.time.Clock()
#self.fps = fps
#self.playtime = 0.0
#self.font = pygame.font.SysFont('mono', 24, bold=True)
self.paint()
评论列表
文章目录