comparison pytouhou/game/enemymanager.py @ 32:47543594ff66

Can't stop optimizing!
author Thibaut Girka <thib@sitedethib.com>
date Sat, 13 Aug 2011 00:14:29 +0200
parents afa91be769ae
children 1f21bcc0845b
comparison
equal deleted inserted replaced
31:55973a3f1222 32:47543594ff66
112 return False 112 return False
113 return True 113 return True
114 114
115 115
116 def update(self, frame): 116 def update(self, frame):
117 #TODO
118 #if not self.script:
119 # return True
120 #if self.script[0][0] == self.frame:
121 # for instr_type, rank_mask, param_mask, args in self.script.pop(0)[1]:
122 # if instr_type == 1: # delete
123 # return False
124 self.ecl_runner.update() 117 self.ecl_runner.update()
125 118
126 x, y = self.x, self.y 119 x, y = self.x, self.y
127 if self.interpolator: 120 if self.interpolator:
128 self.interpolator.update(self.frame) 121 self.interpolator.update(self.frame)
151 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]]) 144 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]])
152 self.direction = None 145 self.direction = None
153 146
154 self.x, self.y = x, y 147 self.x, self.y = x, y
155 if self.sprite: 148 if self.sprite:
156 if self.sprite.update() and self.is_visible(384, 448): #TODO: screen size 149 changed = self.sprite.update()
150 visible = self.is_visible(384, 448)
151 if changed and visible:
157 self.sprite.update_uvs_vertices() 152 self.sprite.update_uvs_vertices()
153 else:
154 visible = False
158 155
159 self.frame += 1 156 self.frame += 1
160 return True 157 return visible
161 158
162 159
163 160
164 class EnemyManager(object): 161 class EnemyManager(object):
165 def __init__(self, stage, anm_wrapper, ecl): 162 def __init__(self, stage, anm_wrapper, ecl):
192 ecl_runner.implementation[1] = ('I', _enemy_deleter) 189 ecl_runner.implementation[1] = ('I', _enemy_deleter)
193 190
194 self.enemies.append(enemy) 191 self.enemies.append(enemy)
195 192
196 # Update enemies 193 # Update enemies
197 for enemy in tuple(self.enemies): 194 visible_enemies = [enemy for enemy in self.enemies if enemy.update(frame)]
198 if not enemy.update(frame):
199 self.enemies.remove(enemy)
200 continue
201 195
202 # Add enemies to vertices/uvs 196 # Add enemies to vertices/uvs
203 self.objects_by_texture = {} 197 self.objects_by_texture = {}
204 for enemy in self.enemies: 198 for enemy in visible_enemies:
205 ox, oy = enemy.x, enemy.y 199 ox, oy = enemy.x, enemy.y
206 if enemy.is_visible(384, 448): #TODO 200 if enemy.is_visible(384, 448): #TODO
207 key = enemy.anm.first_name, enemy.anm.secondary_name 201 key = enemy.anm.first_name, enemy.anm.secondary_name
208 if not key in self.objects_by_texture: 202 if not key in self.objects_by_texture:
209 self.objects_by_texture[key] = (0, [], []) 203 self.objects_by_texture[key] = (0, [], [])