6 class VidException(Exception):
10 def __init__(self, wad):
13 self.tinttab = map(ord, 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 = map (ord, 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)
33 screen[0:w,y] = img[start:end]
35 def __blitPatch(self, data, x, y, trans = None):
36 (width, height) = struct.unpack_from ('<hh', data, 0)
37 (left_offset, top_offset) = struct.unpack_from('<hh', data, 4)
39 # Transform data into a usable form, seeing as it came from a file.
46 # Blit the patch to the screen per-column
47 screen = pygame.surfarray.pixels2d (self.screen)
49 blit = lambda s0,s1,x0,y0,y1: img[s0:s1]
52 blit = lambda s0,s1,x0,y0,y1: map(trans, img[s0:s1], screen[x0,y0:y1])
54 for x_ofs in xrange (width):
55 col_ofs = struct.unpack_from ('<i', data, 8 + 4 * x_ofs)[0]
57 # Step through the posts in a column
59 topdelta = img[col_ofs + 0]
62 length = img[col_ofs + 1]
67 screen[dst_x,y0:y1] = blit(s0,s1,dst_x,y0,y1)
72 self.window = pygame.display.set_mode ((320,200), 0, 8)
73 pygame.display.set_caption('PyHexen')
74 self.screen = pygame.display.get_surface()
76 def DrawRawScreen(self, lump):
77 self.__blitRaw (lump, 320, 200)
79 def DrawPatch(self, x, y, lump):
80 self.__blitPatch (lump, x, y)
82 def DrawFuzzPatch(self, x, y, lump):
83 transparent = lambda a, b: self.tinttab[a + b * 256]
84 self.__blitPatch (lump, x, y, transparent)
86 def DrawShadowedPatch(self, x, y, lump):
87 shadow = lambda a,b: self.tinttab[b * 256]
88 self.__blitPatch (lump, x + 2, y + 2, shadow)
89 self.__blitPatch (lump, x, y)