comparison pytouhou/game/enemymanager.py @ 56:299de3a9b69f

Filter out off-screen enemies (the same way the official game does)
author Thibaut Girka <thib@sitedethib.com>
date Tue, 23 Aug 2011 00:15:22 +0200
parents ab826bc29aa2
children 694f25881d0f
comparison
equal deleted inserted replaced
55:de358a7684c8 56:299de3a9b69f
28 self._anm_wrapper = anm_wrapper 28 self._anm_wrapper = anm_wrapper
29 self._anm = None 29 self._anm = None
30 self._sprite = None 30 self._sprite = None
31 self._removed = False 31 self._removed = False
32 self._type = _type 32 self._type = _type
33 self._was_visible = False
33 34
34 self.frame = 0 35 self.frame = 0
35 36
36 self.x, self.y = pos 37 self.x, self.y = pos
37 self.life = life 38 self.life = life
106 max_x = tw / 2. 107 max_x = tw / 2.
107 max_y = th / 2. 108 max_y = th / 2.
108 min_x = -max_x 109 min_x = -max_x
109 min_y = -max_y 110 min_y = -max_y
110 111
111 if any((min_x >= screen_width - self.x, 112 if any((min_x > screen_width - self.x,
112 max_x <= -self.x, 113 max_x < -self.x,
113 min_y >= screen_height - self.y, 114 min_y > screen_height - self.y,
114 max_y <= -self.y)): 115 max_y < -self.y)):
115 return False 116 return False
116 return True 117 return True
117 118
118 119
119 def get_objects_by_texture(self): 120 def get_objects_by_texture(self):
223 # Filter of destroyed enemies 224 # Filter of destroyed enemies
224 self.enemies[:] = (enemy for enemy in self.enemies if not enemy._removed) 225 self.enemies[:] = (enemy for enemy in self.enemies if not enemy._removed)
225 226
226 # Update enemies 227 # Update enemies
227 visible_enemies = [enemy for enemy in self.enemies if enemy.update(frame)] 228 visible_enemies = [enemy for enemy in self.enemies if enemy.update(frame)]
229 for enemy in visible_enemies:
230 enemy._was_visible = True
231
232 # Filter out-of-screen enemies
233 for enemy in tuple(self.enemies):
234 if enemy._was_visible and not enemy in visible_enemies:
235 enemy._removed = True
236 self.enemies.remove(enemy)
228 237
229 # Add enemies to vertices/uvs 238 # Add enemies to vertices/uvs
230 self.objects_by_texture = {} 239 self.objects_by_texture = {}
231 for enemy in visible_enemies: 240 for enemy in visible_enemies:
232 if enemy.is_visible(384, 448): #TODO 241 if enemy.is_visible(384, 448): #TODO