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