Mercurial > touhou
comparison pytouhou/game/sprite.py @ 37:a10e3f44a883
Add alpha (anm0 instruction 3) support
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 14 Aug 2011 18:00:06 +0200 |
parents | 4d93d45ecb62 |
children | cb5b27011044 |
comparison
equal
deleted
inserted
replaced
36:f46c18872796 | 37:a10e3f44a883 |
---|---|
26 self.corner_relative_placement = False | 26 self.corner_relative_placement = False |
27 self.instruction_pointer = 0 | 27 self.instruction_pointer = 0 |
28 self.keep_still = False | 28 self.keep_still = False |
29 self.playing = True | 29 self.playing = True |
30 self.frame = 0 | 30 self.frame = 0 |
31 self.alpha = 255 | |
31 self._uvs = [] | 32 self._uvs = [] |
32 self._vertices = [] | 33 self._vertices = [] |
34 self._colors = [] | |
33 | 35 |
34 | 36 |
35 def update_uvs_vertices(self, override_width=0, override_height=0): | 37 def update_vertices_uvs_colors(self, override_width=0, override_height=0): |
36 vertmat = Matrix([[-.5, .5, .5, -.5], | 38 vertmat = Matrix([[-.5, .5, .5, -.5], |
37 [-.5, -.5, .5, .5], | 39 [-.5, -.5, .5, .5], |
38 [ .0, .0, .0, .0], | 40 [ .0, .0, .0, .0], |
39 [ 1., 1., 1., 1.]]) | 41 [ 1., 1., 1., 1.]]) |
40 | 42 |
64 ((tx + tw) * x_1, 1. - ((ty + th) * y_1)), | 66 ((tx + tw) * x_1, 1. - ((ty + th) * y_1)), |
65 (tx * x_1, 1. - ((ty + th) * y_1))] | 67 (tx * x_1, 1. - ((ty + th) * y_1))] |
66 | 68 |
67 d = vertmat.data | 69 d = vertmat.data |
68 assert (d[3][0], d[3][1], d[3][2], d[3][3]) == (1., 1., 1., 1.) | 70 assert (d[3][0], d[3][1], d[3][2], d[3][3]) == (1., 1., 1., 1.) |
71 self._colors = [(255, 255, 255, self.alpha)] * 4 | |
69 self._uvs, self._vertices = uvs, zip(d[0], d[1], d[2]) | 72 self._uvs, self._vertices = uvs, zip(d[0], d[1], d[2]) |
70 | 73 |
71 | 74 |
72 | 75 |
73 def update(self): | 76 def update(self): |
81 try: | 84 try: |
82 while frame <= self.frame: | 85 while frame <= self.frame: |
83 frame, instr_type, data = script[self.instruction_pointer] | 86 frame, instr_type, data = script[self.instruction_pointer] |
84 if frame == self.frame: | 87 if frame == self.frame: |
85 changed = True | 88 changed = True |
89 if instr_type == 0: | |
90 self.playing = False | |
91 return False | |
86 if instr_type == 1: | 92 if instr_type == 1: |
87 self.texcoords = self.anm.sprites[unpack('<I', data)[0]] | 93 self.texcoords = self.anm.sprites[unpack('<I', data)[0]] |
88 elif instr_type == 2: | 94 elif instr_type == 2: |
89 self.rescale = unpack('<ff', data) | 95 self.rescale = unpack('<ff', data) |
96 elif instr_type == 3: | |
97 self.alpha = unpack('<I', data)[0] % 256 #TODO | |
90 elif instr_type == 5: | 98 elif instr_type == 5: |
91 self.frame, = unpack('<I', data) | 99 self.frame, = unpack('<I', data) |
92 self.instruction_pointer = 0 | 100 self.instruction_pointer = 0 |
93 elif instr_type == 7: | 101 elif instr_type == 7: |
94 self.mirrored = True | 102 self.mirrored = True |