Mercurial > touhou
comparison pytouhou/game/enemymanager.py @ 94:ca571697ec83
Various minor optimisations and refactoring
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 04 Sep 2011 20:04:00 +0200 |
parents | d167280a82fc |
children | ac2e5e1c2c3c |
comparison
equal
deleted
inserted
replaced
93:d167280a82fc | 94:ca571697ec83 |
---|---|
178 bullet.get_objects_by_texture(objects_by_texture) | 178 bullet.get_objects_by_texture(objects_by_texture) |
179 | 179 |
180 if not self._sprite: | 180 if not self._sprite: |
181 return | 181 return |
182 | 182 |
183 self._sprite.update_vertices_uvs_colors() | 183 sprite = self._sprite |
184 | 184 sprite.update_vertices_uvs_colors() |
185 key = self._sprite.anm.first_name, self._sprite.anm.secondary_name | 185 |
186 key = (key, self._sprite.blendfunc) | 186 key = sprite.anm.first_name, sprite.anm.secondary_name |
187 if not key in objects_by_texture: | 187 key = (key, sprite.blendfunc) |
188 objects_by_texture[key] = (0, [], [], []) | 188 rec = objects_by_texture.setdefault(key, ([], [], [])) |
189 vertices = tuple((x + self.x, y + self.y, z) for x, y, z in self._sprite._vertices) | 189 vertices = ((x + self.x, y + self.y, z) for x, y, z in sprite._vertices) |
190 objects_by_texture[key][1].extend(vertices) | 190 rec[0].extend(vertices) |
191 objects_by_texture[key][2].extend(self._sprite._uvs) | 191 rec[1].extend(sprite._uvs) |
192 objects_by_texture[key][3].extend(self._sprite._colors) | 192 rec[2].extend(sprite._colors) |
193 | 193 |
194 | 194 |
195 def update(self): | 195 def update(self): |
196 x, y = self.x, self.y | 196 x, y = self.x, self.y |
197 if self.interpolator: | 197 if self.interpolator: |
317 self.enemies[:] = (enemy for enemy in self.enemies if not enemy._removed) | 317 self.enemies[:] = (enemy for enemy in self.enemies if not enemy._removed) |
318 | 318 |
319 # Update enemies | 319 # Update enemies |
320 for enemy in self.enemies: | 320 for enemy in self.enemies: |
321 enemy.update() | 321 enemy.update() |
322 for bullet in enemy.bullets: | 322 for bullet in tuple(enemy.bullets): |
323 if bullet._launched: | 323 if bullet._launched: |
324 enemy.bullets.remove(bullet) | 324 enemy.bullets.remove(bullet) |
325 self.bullets.append(bullet) | 325 self.bullets.append(bullet) |
326 | 326 |
327 # Update bullets | 327 # Update bullets |
338 if enemy._was_visible and not enemy in visible_enemies: | 338 if enemy._was_visible and not enemy in visible_enemies: |
339 enemy._removed = True | 339 enemy._removed = True |
340 self.enemies.remove(enemy) | 340 self.enemies.remove(enemy) |
341 | 341 |
342 # Filter out-of-scren bullets | 342 # Filter out-of-scren bullets |
343 for bullet in self.bullets: | 343 for bullet in tuple(self.bullets): |
344 if not bullet.is_visible(384, 448): | 344 if not bullet.is_visible(384, 448): |
345 self.bullets.remove(bullet) | 345 self.bullets.remove(bullet) |
346 | 346 |
347 | 347 |
348 #TODO: disable boss mode if it is dead/it has timeout | 348 #TODO: disable boss mode if it is dead/it has timeout |