Mercurial > touhou
comparison pytouhou/game/enemy.py @ 106:c7847bfed427
Minor refactoring
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 05 Sep 2011 22:40:46 +0200 |
parents | 572740acdb25 |
children | 2a03940deea3 |
comparison
equal
deleted
inserted
replaced
105:572740acdb25 | 106:c7847bfed427 |
---|---|
41 self.life = life | 41 self.life = life |
42 self.max_life = life | 42 self.max_life = life |
43 self.touchable = True | 43 self.touchable = True |
44 self.damageable = True | 44 self.damageable = True |
45 self.death_flags = 0 | 45 self.death_flags = 0 |
46 self.bullets = [] | |
47 self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.) | 46 self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.) |
48 self.bullet_attributes = None | 47 self.bullet_attributes = None |
49 self.bullet_launch_offset = (0, 0) | 48 self.bullet_launch_offset = (0, 0) |
50 self.death_callback = None | 49 self.death_callback = None |
51 self.boss_callback = None | 50 self.boss_callback = None |
103 if type_ == 71: | 102 if type_ == 71: |
104 launch_angle += pi / bullets_per_shot | 103 launch_angle += pi / bullets_per_shot |
105 if type_ != 75: | 104 if type_ != 75: |
106 launch_angle -= angle * (bullets_per_shot - 1) / 2. | 105 launch_angle -= angle * (bullets_per_shot - 1) / 2. |
107 | 106 |
107 bullets = self._game_state.bullets | |
108 | |
108 for shot_nb in range(number_of_shots): | 109 for shot_nb in range(number_of_shots): |
109 shot_speed = speed if shot_nb == 0 else speed + (speed2 - speed) * float(shot_nb) / float(number_of_shots) | 110 shot_speed = speed if shot_nb == 0 else speed + (speed2 - speed) * float(shot_nb) / float(number_of_shots) |
110 bullet_angle = launch_angle | 111 bullet_angle = launch_angle |
111 for bullet_nb in range(bullets_per_shot): | 112 for bullet_nb in range(bullets_per_shot): |
112 if type_ == 75: # 102.h@0x4138cf | 113 if type_ == 75: # 102.h@0x4138cf |
113 bullet_angle = self._game_state.prng.rand_double() * (launch_angle - angle) + angle | 114 bullet_angle = self._game_state.prng.rand_double() * (launch_angle - angle) + angle |
114 shot_speed = self._game_state.prng.rand_double() * (speed - speed2) + speed2 | 115 shot_speed = self._game_state.prng.rand_double() * (speed - speed2) + speed2 |
115 self.bullets.append(Bullet((self.x, self.y), | 116 bullets.append(Bullet((self.x, self.y), |
116 anim, sprite_idx_offset, | 117 anim, sprite_idx_offset, |
117 bullet_angle, shot_speed, | 118 bullet_angle, shot_speed, |
118 self.extended_bullet_attributes, | 119 self.extended_bullet_attributes, |
119 flags, player, self._game_state)) | 120 flags, player, self._game_state)) |
120 bullet_angle += angle | 121 bullet_angle += angle |
121 | 122 |
122 | 123 |
123 def select_player(self, players=None): | 124 def select_player(self, players=None): |
124 return (players or self._game_state.players)[0] #TODO | 125 return (players or self._game_state.players)[0] #TODO |
182 return False | 183 return False |
183 return True | 184 return True |
184 | 185 |
185 | 186 |
186 def get_objects_by_texture(self, objects_by_texture): | 187 def get_objects_by_texture(self, objects_by_texture): |
187 for bullet in self.bullets: | |
188 bullet.get_objects_by_texture(objects_by_texture) | |
189 | |
190 if not self._sprite: | 188 if not self._sprite: |
191 return | 189 return |
192 | 190 |
193 sprite = self._sprite | 191 sprite = self._sprite |
194 sprite.update_vertices_uvs_colors() | 192 sprite.update_vertices_uvs_colors() |
263 if self.bullet_launch_interval != 0: | 261 if self.bullet_launch_interval != 0: |
264 self.bullet_launch_timer += 1 | 262 self.bullet_launch_timer += 1 |
265 if self.bullet_launch_timer == self.bullet_launch_interval: | 263 if self.bullet_launch_timer == self.bullet_launch_interval: |
266 self.fire() | 264 self.fire() |
267 | 265 |
268 | |
269 for bullet in self.bullets: | |
270 bullet.update() | |
271 | |
272 | |
273 self.frame += 1 | 266 self.frame += 1 |
274 | 267 |