comparison pytouhou/game/game.py @ 428:f41a26971a19

Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 16 Jul 2013 21:17:22 +0200
parents 608468be7a93
children c9433188ffdb
comparison
equal deleted inserted replaced
427:0604f4fbbe3c 428:f41a26971a19
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 from itertools import chain 15 from itertools import chain
16 16
17 from pytouhou.vm.eclrunner import ECLMainRunner
18 from pytouhou.vm.msgrunner import MSGRunner 17 from pytouhou.vm.msgrunner import MSGRunner
19 18
20 from pytouhou.game.bullet import LAUNCHED, CANCELLED 19 from pytouhou.game.bullet import LAUNCHED, CANCELLED
21 from pytouhou.game.enemy import Enemy 20 from pytouhou.game.enemy import Enemy
22 from pytouhou.game.item import Item 21 from pytouhou.game.item import Item
29 class GameOver(Exception): 28 class GameOver(Exception):
30 pass 29 pass
31 30
32 31
33 class Game(object): 32 class Game(object):
34 def __init__(self, resource_loader, players, stage, rank, difficulty, 33 def __init__(self, players, stage, rank, difficulty, bullet_types,
35 bullet_types, laser_types, item_types, 34 laser_types, item_types, nb_bullets_max=None, width=384,
36 nb_bullets_max=None, width=384, height=448, prng=None, 35 height=448, prng=None, interface=None, continues=0,
37 interface=None, continues=0, hints=None): 36 hints=None):
38 self.resource_loader = resource_loader
39
40 self.width, self.height = width, height 37 self.width, self.height = width, height
41 38
42 self.nb_bullets_max = nb_bullets_max 39 self.nb_bullets_max = nb_bullets_max
43 self.bullet_types = bullet_types 40 self.bullet_types = bullet_types
44 self.laser_types = laser_types 41 self.laser_types = laser_types
73 self.bonus_list = [0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 70 self.bonus_list = [0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0,
74 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 2] 71 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 2]
75 self.prng = prng 72 self.prng = prng
76 self.frame = 0 73 self.frame = 0
77 74
78 self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage,
79 'stg%denm2.anm' % stage))
80 self.etama4 = resource_loader.get_anm_wrapper(('etama4.anm',))
81 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
82 self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains]
83
84 self.spellcard_effect_anm_wrapper = resource_loader.get_anm_wrapper(('eff0%d.anm' % stage,))
85 self.spellcard_effect = None 75 self.spellcard_effect = None
86 76
87 # See 102h.exe@0x413220 if you think you're brave enough. 77 # See 102h.exe@0x413220 if you think you're brave enough.
88 self.deaths_count = self.prng.rand_uint16() % 3 78 self.deaths_count = self.prng.rand_uint16() % 3
89 self.next_bonus = self.prng.rand_uint16() % 8 79 self.next_bonus = self.prng.rand_uint16() % 8
185 175
186 176
187 def new_effect(self, pos, anim, anm_wrapper=None, number=1): 177 def new_effect(self, pos, anim, anm_wrapper=None, number=1):
188 number = min(number, self.nb_bullets_max - len(self.effects)) 178 number = min(number, self.nb_bullets_max - len(self.effects))
189 for i in xrange(number): 179 for i in xrange(number):
190 self.effects.append(Effect(pos, anim, anm_wrapper or self.etama4)) 180 self.effects.append(Effect(pos, anim, anm_wrapper or self.etama))
191 181
192 182
193 def new_particle(self, pos, anim, amp, number=1, reverse=False, duration=24): 183 def new_particle(self, pos, anim, amp, number=1, reverse=False, duration=24):
194 number = min(number, self.nb_bullets_max - len(self.effects)) 184 number = min(number, self.nb_bullets_max - len(self.effects))
195 for i in xrange(number): 185 for i in xrange(number):
196 self.effects.append(Particle(pos, anim, self.etama4, amp, self, reverse=reverse, duration=duration)) 186 self.effects.append(Particle(pos, anim, self.etama, amp, self, reverse=reverse, duration=duration))
197 187
198 188
199 def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score): 189 def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score):
200 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self) 190 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self)
201 self.enemies.append(enemy) 191 self.enemies.append(enemy)