comparison pytouhou/game/enemy.py @ 123:d1c82d43bbf3

Various optimizations
author Thibaut Girka <thib@sitedethib.com>
date Sat, 10 Sep 2011 11:58:24 +0200
parents 4300a832f033
children 11ab06f4c4c6
comparison
equal deleted inserted replaced
122:174324a4da51 123:d1c82d43bbf3
83 if not self.delay_attack: 83 if not self.delay_attack:
84 self.fire() 84 self.fire()
85 85
86 86
87 def fire(self): 87 def fire(self):
88 (type_, anim, sprite_idx_offset, bullets_per_shot, number_of_shots, 88 (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots,
89 speed, speed2, launch_angle, angle, flags) = self.bullet_attributes 89 speed, speed2, launch_angle, angle, flags) = self.bullet_attributes
90
91 bullet_type = self._game_state.bullet_types[type_idx]
90 92
91 ox, oy = self.bullet_launch_offset 93 ox, oy = self.bullet_launch_offset
92 launch_pos = self.x + ox, self.y + oy 94 launch_pos = self.x + ox, self.y + oy
93 95
94 if speed2 < 0.3: 96 if speed2 < 0.3:
114 bullet_angle = launch_angle 116 bullet_angle = launch_angle
115 for bullet_nb in range(bullets_per_shot): 117 for bullet_nb in range(bullets_per_shot):
116 if type_ == 75: # 102.h@0x4138cf 118 if type_ == 75: # 102.h@0x4138cf
117 bullet_angle = self._game_state.prng.rand_double() * (launch_angle - angle) + angle 119 bullet_angle = self._game_state.prng.rand_double() * (launch_angle - angle) + angle
118 shot_speed = self._game_state.prng.rand_double() * (speed - speed2) + speed2 120 shot_speed = self._game_state.prng.rand_double() * (speed - speed2) + speed2
119 bullets.append(Bullet(launch_pos, anim, sprite_idx_offset, 121 bullets.append(Bullet(launch_pos, bullet_type, sprite_idx_offset,
120 bullet_angle, shot_speed, 122 bullet_angle, shot_speed,
121 self.extended_bullet_attributes, 123 self.extended_bullet_attributes,
122 flags, player, self._game_state)) 124 flags, player, self._game_state))
123 bullet_angle += angle 125 bullet_angle += angle
124 126
171 if self._sprite.corner_relative_placement: 173 if self._sprite.corner_relative_placement:
172 raise Exception #TODO 174 raise Exception #TODO
173 else: 175 else:
174 tx, ty, tw, th = 0., 0., 0., 0. 176 tx, ty, tw, th = 0., 0., 0., 0.
175 177
178 x, y = self.x, self.y
176 max_x = tw / 2. 179 max_x = tw / 2.
177 max_y = th / 2. 180 max_y = th / 2.
178 min_x = -max_x 181
179 min_y = -max_y 182 if (max_x < x - screen_width
180 183 or max_x < -x
181 if any((min_x > screen_width - self.x, 184 or max_y < y - screen_height
182 max_x < -self.x, 185 or max_y < -y):
183 min_y > screen_height - self.y,
184 max_y < -self.y)):
185 return False 186 return False
186 return True 187 return True
187 188
188 189
189 def update(self): 190 def update(self):