5 class VidException(Exception):
9 def __init__(self, wad):
12 self.tinttab = self.wad.CacheLumpName ('TINTTAB')
14 # Stuff from I_* in the C code.
15 def SetPalette(self, data):
17 for i in range (0, 768, 3):
18 rgb = [ord(x) for x in data[i:i+3]]
19 self.palette.append(rgb)
20 self.screen.set_palette(self.palette)
25 # Stuff from V_* in the C code.
26 def __blitRaw (self, data, w, h):
27 screen = pygame.surfarray.pixels2d (self.screen)
29 for x in range (0, w):
30 screen[x,y] = ord (data[y * w + x])
32 def __blitPatch(self, data, x, y, trans = lambda a, b: a):
33 (width, height) = struct.unpack_from ('<hh', data, 0)
34 (left_offset, top_offset) = struct.unpack_from('<hh', data, 4)
40 # Crazy column/patch thing to buffer
41 screen = pygame.surfarray.pixels2d (self.screen)
42 for x_ofs in range (0, width):
43 col_ofs = struct.unpack_from ('<i', data, 8 + 4 * x_ofs)[0]
44 topdelta = ord (data[col_ofs + 0])
45 # Step through the posts in a column
46 while topdelta != 255:
47 length = ord (data[col_ofs + 1])
48 source_ofs = col_ofs + 3
49 topdelta = topdelta + y
50 for y_ofs in range (0, length):
51 screen[x + x_ofs, topdelta + y_ofs] = trans(ord (data[source_ofs + y_ofs]),screen[x + x_ofs, topdelta + y_ofs])
52 col_ofs = col_ofs + length + 4
53 topdelta = ord (data[col_ofs + 0])
57 self.window = pygame.display.set_mode ((320,200), 0, 8)
58 pygame.display.set_caption('PyHexen')
59 self.screen = pygame.display.get_surface()
61 def DrawRawScreen(self, lump):
62 self.__blitRaw (lump, 320, 200)
64 def DrawPatch(self, x, y, lump):
65 self.__blitPatch (lump, x, y)
67 def DrawFuzzPatch(self, x, y, lump):
68 transparent = lambda a, b: ord (self.tinttab[a + b * 256])
69 self.__blitPatch (lump, x, y, transparent)
71 def DrawShadowedPatch(self, x, y, lump):
72 shadow = lambda a,b: ord (self.tinttab[b * 256])
73 self.__blitPatch (lump, x + 2, y + 2, shadow)
74 self.__blitPatch (lump, x, y)