comparison pytouhou/game/enemymanager.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 f46c18872796
children ce662b372ee0
comparison
equal deleted inserted replaced
36:f46c18872796 37:a10e3f44a883
121 121
122 def get_objects_by_texture(self): 122 def get_objects_by_texture(self):
123 objects_by_texture = {} 123 objects_by_texture = {}
124 key = self.anm.first_name, self.anm.secondary_name 124 key = self.anm.first_name, self.anm.secondary_name
125 if not key in objects_by_texture: 125 if not key in objects_by_texture:
126 objects_by_texture[key] = (0, [], []) 126 objects_by_texture[key] = (0, [], [], [])
127 vertices = tuple((x + self.x, y + self.y, z) for x, y, z in self.sprite._vertices) 127 vertices = tuple((x + self.x, y + self.y, z) for x, y, z in self.sprite._vertices)
128 objects_by_texture[key][1].extend(vertices) 128 objects_by_texture[key][1].extend(vertices)
129 objects_by_texture[key][2].extend(self.sprite._uvs) 129 objects_by_texture[key][2].extend(self.sprite._uvs)
130 objects_by_texture[key][3].extend(self.sprite._colors)
130 #TODO: effects/bullet launch 131 #TODO: effects/bullet launch
131 return objects_by_texture 132 return objects_by_texture
132 133
133 134
134 def update(self, frame): 135 def update(self, frame):
164 self.x, self.y = x, y 165 self.x, self.y = x, y
165 if self.sprite: 166 if self.sprite:
166 changed = self.sprite.update() 167 changed = self.sprite.update()
167 visible = self.is_visible(384, 448) 168 visible = self.is_visible(384, 448)
168 if changed and visible: 169 if changed and visible:
169 self.sprite.update_uvs_vertices() 170 self.sprite.update_vertices_uvs_colors()
170 elif not self.sprite.playing: 171 elif not self.sprite.playing:
171 visible = False 172 visible = False
172 self.sprite = None 173 self.sprite = None
173 else: 174 else:
174 visible = False 175 visible = False
218 219
219 # Add enemies to vertices/uvs 220 # Add enemies to vertices/uvs
220 self.objects_by_texture = {} 221 self.objects_by_texture = {}
221 for enemy in visible_enemies: 222 for enemy in visible_enemies:
222 if enemy.is_visible(384, 448): #TODO 223 if enemy.is_visible(384, 448): #TODO
223 for key, (count, vertices, uvs) in enemy.get_objects_by_texture().items(): 224 for key, (count, vertices, uvs, colors) in enemy.get_objects_by_texture().items():
224 if not key in self.objects_by_texture: 225 if not key in self.objects_by_texture:
225 self.objects_by_texture[key] = (0, [], []) 226 self.objects_by_texture[key] = (0, [], [], [])
226 self.objects_by_texture[key][1].extend(vertices) 227 self.objects_by_texture[key][1].extend(vertices)
227 self.objects_by_texture[key][2].extend(uvs) 228 self.objects_by_texture[key][2].extend(uvs)
228 for key, (nb_vertices, vertices, uvs) in self.objects_by_texture.items(): 229 self.objects_by_texture[key][3].extend(colors)
230 for key, (nb_vertices, vertices, uvs, colors) in self.objects_by_texture.items():
229 nb_vertices = len(vertices) 231 nb_vertices = len(vertices)
230 vertices = pack('f' * (3 * nb_vertices), *chain(*vertices)) 232 vertices = pack('f' * (3 * nb_vertices), *chain(*vertices))
231 uvs = pack('f' * (2 * nb_vertices), *chain(*uvs)) 233 uvs = pack('f' * (2 * nb_vertices), *chain(*uvs))
232 self.objects_by_texture[key] = (nb_vertices, vertices, uvs) 234 colors = pack('B' * (4 * nb_vertices), *chain(*colors))
233 235 self.objects_by_texture[key] = (nb_vertices, vertices, uvs, colors)
236