comparison pytouhou/game/game.py @ 388:ac2891afb0bb

Make particles behave as in the original game.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 21 Oct 2012 23:02:40 +0200
parents c25530efea3b
children b11953cf1d3b
comparison
equal deleted inserted replaced
387:e1f5dcd4b83e 388:ac2891afb0bb
18 from pytouhou.vm.msgrunner import MSGRunner 18 from pytouhou.vm.msgrunner import MSGRunner
19 19
20 from pytouhou.game.bullet import LAUNCHED, CANCELLED 20 from pytouhou.game.bullet import LAUNCHED, CANCELLED
21 from pytouhou.game.enemy import Enemy 21 from pytouhou.game.enemy import Enemy
22 from pytouhou.game.item import Item 22 from pytouhou.game.item import Item
23 from pytouhou.game.effect import Effect 23 from pytouhou.game.effect import Effect, Particle
24 from pytouhou.game.effect import Particle
25 from pytouhou.game.text import Text 24 from pytouhou.game.text import Text
26 25
27 26
28 27
29 class GameOver(Exception): 28 class GameOver(Exception):
183 #TODO: check 182 #TODO: check
184 enemy.process.switch_to_sub(enemy.death_callback) 183 enemy.process.switch_to_sub(enemy.death_callback)
185 enemy.death_callback = -1 184 enemy.death_callback = -1
186 185
187 186
188 def new_effect(self, pos, anim, anm_wrapper=None): 187 def new_effect(self, pos, anim, anm_wrapper=None, number=1):
189 self.effects.append(Effect(pos, anim, anm_wrapper or self.etama4)) 188 number = min(number, self.nb_bullets_max - len(self.effects))
190 189 for i in xrange(number):
191 190 self.effects.append(Effect(pos, anim, anm_wrapper or self.etama4))
192 def new_particle(self, pos, color, size, amp): 191
193 self.effects.append(Particle(pos, 7 + 4 * color + self.prng.rand_uint16() % 4, self.etama4, size, amp, self)) 192
193 def new_particle(self, pos, anim, amp, number=1, reverse=False, duration=24):
194 number = min(number, self.nb_bullets_max - len(self.effects))
195 for i in xrange(number):
196 self.effects.append(Particle(pos, anim, self.etama4, amp, self, reverse=reverse, duration=duration))
194 197
195 198
196 def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score): 199 def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score):
197 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self) 200 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self)
198 self.enemies.append(enemy) 201 self.enemies.append(enemy)
331 elif laser.check_grazing((px, py)): 334 elif laser.check_grazing((px, py)):
332 player.state.graze += 1 #TODO 335 player.state.graze += 1 #TODO
333 player.state.score += 500 #TODO 336 player.state.score += 500 #TODO
334 player.play_sound('graze') 337 player.play_sound('graze')
335 self.modify_difficulty(+6) #TODO 338 self.modify_difficulty(+6) #TODO
336 self.new_particle((px, py), 0, .8, 192) #TODO 339 self.new_particle((px, py), 9, 192) #TODO
337 340
338 for bullet in self.bullets: 341 for bullet in self.bullets:
339 if bullet.state != LAUNCHED: 342 if bullet.state != LAUNCHED:
340 continue 343 continue
341 344
355 bullet.grazed = True 358 bullet.grazed = True
356 player.state.graze += 1 359 player.state.graze += 1
357 player.state.score += 500 # found experimentally 360 player.state.score += 500 # found experimentally
358 player.play_sound('graze') 361 player.play_sound('graze')
359 self.modify_difficulty(+6) 362 self.modify_difficulty(+6)
360 self.new_particle((px, py), 0, .8, 192) #TODO: find the real size and range. 363 self.new_particle((px, py), 9, 192) #TODO: find the real size and range.
361 #TODO: display a static particle during one frame at 364 #TODO: display a static particle during one frame at
362 # 12 pixels of the player, in the axis of the “collision”. 365 # 12 pixels of the player, in the axis of the “collision”.
363 366
364 #TODO: is it the right place? 367 #TODO: is it the right place?
365 if py < 128 and player.state.power >= 128: #TODO: check py. 368 if py < 128 and player.state.power >= 128: #TODO: check py.