comparison pytouhou/game/enemymanager.py @ 29:afa91be769ae

Don't lose time updating off-screen enemies' sprites
author Thibaut Girka <thib@sitedethib.com>
date Fri, 12 Aug 2011 22:03:34 +0200
parents 444ac7bca7bc
children 47543594ff66
comparison
equal deleted inserted replaced
28:f405b947624d 29:afa91be769ae
93 93
94 94
95 def is_visible(self, screen_width, screen_height): 95 def is_visible(self, screen_width, screen_height):
96 if not self.sprite: 96 if not self.sprite:
97 return False 97 return False
98 if min(x for x, y, z in self.sprite._vertices) >= screen_width - self.x: 98
99 return False 99 tx, ty, tw, th = self.sprite.texcoords
100 if max(x for x, y, z in self.sprite._vertices) <= -self.x: 100 if self.sprite.corner_relative_placement:
101 return False 101 raise Exception #TODO
102 if min(y for x, y, z in self.sprite._vertices) >= screen_height - self.y: 102 else:
103 return False 103 max_x = tw / 2.
104 if max(y for x, y, z in self.sprite._vertices) <= -self.y: 104 max_y = th / 2.
105 min_x = -max_x
106 min_y = -max_y
107
108 if any((min_x >= screen_width - self.x,
109 max_x <= -self.x,
110 min_y >= screen_height - self.y,
111 max_y <= -self.y)):
105 return False 112 return False
106 return True 113 return True
107 114
108 115
109 def update(self, frame): 116 def update(self, frame):
144 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]]) 151 self.anm, self.sprite = self.anm_wrapper.get_sprite(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]])
145 self.direction = None 152 self.direction = None
146 153
147 self.x, self.y = x, y 154 self.x, self.y = x, y
148 if self.sprite: 155 if self.sprite:
149 self.sprite.update() 156 if self.sprite.update() and self.is_visible(384, 448): #TODO: screen size
157 self.sprite.update_uvs_vertices()
150 158
151 self.frame += 1 159 self.frame += 1
152 return True 160 return True
153 161
154 162
177 x, y, z, life, unknown1, unknown2, unknown3 = args 185 x, y, z, life, unknown1, unknown2, unknown3 = args
178 ecl_runner = ECLRunner(self.ecl, sub) 186 ecl_runner = ECLRunner(self.ecl, sub)
179 enemy = Enemy((x, y), life, instr_type, ecl_runner, self.anm_wrapper) 187 enemy = Enemy((x, y), life, instr_type, ecl_runner, self.anm_wrapper)
180 188
181 def _enemy_deleter(unknown): #TOOD: unknown 189 def _enemy_deleter(unknown): #TOOD: unknown
182 print('youhou!')
183 self.enemies.remove(enemy) 190 self.enemies.remove(enemy)
184 191
185 ecl_runner.implementation[1] = ('I', _enemy_deleter) 192 ecl_runner.implementation[1] = ('I', _enemy_deleter)
186 193
187 self.enemies.append(enemy) 194 self.enemies.append(enemy)