comparison pytouhou/games/eosd.py @ 434:18e4b121646b

Move the common parts of EoSDGame outside, to not reallocate them at each stage.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 11 Aug 2013 14:30:52 +0200
parents c9433188ffdb
children cae1ae9de430
comparison
equal deleted inserted replaced
433:1222341ea22c 434:18e4b121646b
25 from pytouhou.game.background import Background 25 from pytouhou.game.background import Background
26 26
27 from pytouhou.vm.eclrunner import ECLMainRunner 27 from pytouhou.vm.eclrunner import ECLMainRunner
28 28
29 29
30 class EoSDCommon(object):
31 def __init__(self, resource_loader):
32 self.etama = resource_loader.get_multi_anm(('etama3.anm', 'etama4.anm'))
33 self.bullet_types = [BulletType(self.etama[0], 0, 11, 14, 15, 16, hitbox_size=2,
34 type_id=0),
35 BulletType(self.etama[0], 1, 12, 17, 18, 19, hitbox_size=3,
36 type_id=1),
37 BulletType(self.etama[0], 2, 12, 17, 18, 19, hitbox_size=2,
38 type_id=2),
39 BulletType(self.etama[0], 3, 12, 17, 18, 19, hitbox_size=3,
40 type_id=3),
41 BulletType(self.etama[0], 4, 12, 17, 18, 19, hitbox_size=2.5,
42 type_id=4),
43 BulletType(self.etama[0], 5, 12, 17, 18, 19, hitbox_size=2,
44 type_id=5),
45 BulletType(self.etama[0], 6, 13, 20, 20, 20, hitbox_size=8,
46 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0),
47 type_id=6),
48 BulletType(self.etama[0], 7, 13, 20, 20, 20, hitbox_size=5.5,
49 launch_anim_offsets=(1,)*28,
50 type_id=7),
51 BulletType(self.etama[0], 8, 13, 20, 20, 20, hitbox_size=4.5,
52 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0),
53 type_id=8),
54 BulletType(self.etama[1], 0, 1, 2, 2, 2, hitbox_size=16,
55 launch_anim_offsets=(0, 1, 2, 3, 4, 5, 6, 7, 8),
56 type_id=9)]
57
58 self.laser_types = [LaserType(self.etama[0], 9),
59 LaserType(self.etama[0], 10)]
60
61 self.item_types = [ItemType(self.etama[0], 0, 7), #Power
62 ItemType(self.etama[0], 1, 8), #Point
63 ItemType(self.etama[0], 2, 9), #Big power
64 ItemType(self.etama[0], 3, 10), #Bomb
65 ItemType(self.etama[0], 4, 11), #Full power
66 ItemType(self.etama[0], 5, 12), #1up
67 ItemType(self.etama[0], 6, 13)] #Star
68
69 self.enemy_face = [('face03a.anm', 'face03b.anm'),
70 ('face05a.anm',),
71 ('face06a.anm', 'face06b.anm'),
72 ('face08a.anm', 'face08b.anm'),
73 ('face09a.anm', 'face09b.anm'),
74 ('face09b.anm', 'face10a.anm', 'face10b.anm'),
75 ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')]
76
77 self.characters = resource_loader.get_eosd_characters()
78 self.interface = EoSDInterface(resource_loader)
79
80
81
30 class EoSDGame(Game): 82 class EoSDGame(Game):
31 def __init__(self, resource_loader, player_states, stage, rank, difficulty, 83 def __init__(self, resource_loader, player_states, stage, rank, difficulty,
32 bullet_types=None, laser_types=None, item_types=None, 84 common, nb_bullets_max=640, width=384, height=448, prng=None,
33 nb_bullets_max=640, width=384, height=448, prng=None,
34 continues=0, hints=None): 85 continues=0, hints=None):
35 86
36 if not bullet_types: 87 self.etama = common.etama #XXX
37 self.etama = resource_loader.get_multi_anm(('etama3.anm', 'etama4.anm'))
38 bullet_types = [BulletType(self.etama[0], 0, 11, 14, 15, 16, hitbox_size=2,
39 type_id=0),
40 BulletType(self.etama[0], 1, 12, 17, 18, 19, hitbox_size=3,
41 type_id=1),
42 BulletType(self.etama[0], 2, 12, 17, 18, 19, hitbox_size=2,
43 type_id=2),
44 BulletType(self.etama[0], 3, 12, 17, 18, 19, hitbox_size=3,
45 type_id=3),
46 BulletType(self.etama[0], 4, 12, 17, 18, 19, hitbox_size=2.5,
47 type_id=4),
48 BulletType(self.etama[0], 5, 12, 17, 18, 19, hitbox_size=2,
49 type_id=5),
50 BulletType(self.etama[0], 6, 13, 20, 20, 20, hitbox_size=8,
51 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0),
52 type_id=6),
53 BulletType(self.etama[0], 7, 13, 20, 20, 20, hitbox_size=5.5,
54 launch_anim_offsets=(1,)*28,
55 type_id=7),
56 BulletType(self.etama[0], 8, 13, 20, 20, 20, hitbox_size=4.5,
57 launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0),
58 type_id=8),
59 BulletType(self.etama[1], 0, 1, 2, 2, 2, hitbox_size=16,
60 launch_anim_offsets=(0, 1, 2, 3, 4, 5, 6, 7, 8),
61 type_id=9)]
62
63 if not laser_types:
64 laser_types = [LaserType(self.etama[0], 9),
65 LaserType(self.etama[0], 10)]
66
67 if not item_types:
68 item_types = [ItemType(self.etama[0], 0, 7), #Power
69 ItemType(self.etama[0], 1, 8), #Point
70 ItemType(self.etama[0], 2, 9), #Big power
71 ItemType(self.etama[0], 3, 10), #Bomb
72 ItemType(self.etama[0], 4, 11), #Full power
73 ItemType(self.etama[0], 5, 12), #1up
74 ItemType(self.etama[0], 6, 13)] #Star
75
76 try: 88 try:
77 self.enm_anm = resource_loader.get_multi_anm(('stg%denm.anm' % stage, 89 self.enm_anm = resource_loader.get_multi_anm(('stg%denm.anm' % stage,
78 'stg%denm2.anm' % stage)) 90 'stg%denm2.anm' % stage))
79 except KeyError: 91 except KeyError:
80 self.enm_anm = resource_loader.get_anm('stg%denm.anm' % stage) 92 self.enm_anm = resource_loader.get_anm('stg%denm.anm' % stage)
82 self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains] 94 self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains]
83 95
84 self.spellcard_effect_anm = resource_loader.get_single_anm('eff0%d.anm' % stage) 96 self.spellcard_effect_anm = resource_loader.get_single_anm('eff0%d.anm' % stage)
85 97
86 player_face = player_states[0].character // 2 98 player_face = player_states[0].character // 2
87 enemy_face = [('face03a.anm', 'face03b.anm'),
88 ('face05a.anm',),
89 ('face06a.anm', 'face06b.anm'),
90 ('face08a.anm', 'face08b.anm'),
91 ('face09a.anm', 'face09b.anm'),
92 ('face09b.anm', 'face10a.anm', 'face10b.anm'),
93 ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')]
94 self.msg = resource_loader.get_msg('msg%d.dat' % stage) 99 self.msg = resource_loader.get_msg('msg%d.dat' % stage)
95 msg_anm = [resource_loader.get_multi_anm(('face0%da.anm' % player_face, 100 msg_anm = [resource_loader.get_multi_anm(('face0%da.anm' % player_face,
96 'face0%db.anm' % player_face, 101 'face0%db.anm' % player_face,
97 'face0%dc.anm' % player_face)), 102 'face0%dc.anm' % player_face)),
98 resource_loader.get_multi_anm(enemy_face[stage - 1])] 103 resource_loader.get_multi_anm(common.enemy_face[stage - 1])]
99 104
100 self.msg_anm = [[], []] 105 self.msg_anm = [[], []]
101 for i, anms in enumerate(msg_anm): 106 for i, anms in enumerate(msg_anm):
102 for anm in anms: 107 for anm in anms:
103 for sprite in anm.sprites.values(): 108 for sprite in anm.sprites.values():
104 self.msg_anm[i].append((anm, sprite)) 109 self.msg_anm[i].append((anm, sprite))
105 110
106 characters = resource_loader.get_eosd_characters() 111 players = [EoSDPlayer(state, self, resource_loader, common.characters[state.character]) for state in player_states]
107 players = [EoSDPlayer(state, self, resource_loader, characters[state.character]) for state in player_states] 112
108 113 common.interface.start_stage(self, stage)
109 self.stage = stage #XXX
110 interface = EoSDInterface(self, resource_loader)
111 114
112 # Load stage data 115 # Load stage data
113 self.std = resource_loader.get_stage('stage%d.std' % stage) 116 self.std = resource_loader.get_stage('stage%d.std' % stage)
114 117
115 background_anm = resource_loader.get_single_anm('stg%dbg.anm' % stage) 118 background_anm = resource_loader.get_single_anm('stg%dbg.anm' % stage)
116 self.background = Background(self.std, background_anm) 119 self.background = Background(self.std, background_anm)
117 120
118 self.resource_loader = resource_loader #XXX: currently used for texture preload in pytouhou.ui.gamerunner. Wipe it! 121 self.resource_loader = resource_loader #XXX: currently used for texture preload in pytouhou.ui.gamerunner. Wipe it!
119 122
120 Game.__init__(self, players, stage, rank, difficulty, 123 Game.__init__(self, players, stage, rank, difficulty,
121 bullet_types, laser_types, item_types, nb_bullets_max, 124 common.bullet_types, common.laser_types,
122 width, height, prng, interface, continues, hints) 125 common.item_types, nb_bullets_max, width, height, prng,
126 common.interface, continues, hints)
123 127
124 128
125 129
126 class EoSDInterface(object): 130 class EoSDInterface(object):
127 def __init__(self, game, resource_loader): 131 def __init__(self, resource_loader):
128 self.game = game 132 self.game = None
129 front = resource_loader.get_single_anm('front.anm') 133 front = resource_loader.get_single_anm('front.anm')
130 self.ascii_anm = resource_loader.get_single_anm('ascii.anm') 134 self.ascii_anm = resource_loader.get_single_anm('ascii.anm')
131 135
132 self.width = 640 136 self.width = 640
133 self.height = 480 137 self.height = 480
141 [Effect((0, 0), 5, front)] + 145 [Effect((0, 0), 5, front)] +
142 [Effect((0, 0), i, front) for i in range(5) + range(9, 16)]) 146 [Effect((0, 0), i, front) for i in range(5) + range(9, 16)])
143 for item in self.items: 147 for item in self.items:
144 item.sprite.allow_dest_offset = True #XXX 148 item.sprite.allow_dest_offset = True #XXX
145 149
146 self.level_start = [Text((176, 200), self.ascii_anm, text='STAGE %d' % game.stage)] #TODO: find the exact location. 150 self.level_start = []
147 self.level_start[0].set_timeout(240, effect='fadeout', duration=60, start=120)
148 self.level_start[0].set_color('yellow')
149 #TODO: use the system text for the stage name, and the song name.
150 151
151 self.labels = { 152 self.labels = {
152 'highscore': Text((500, 58), self.ascii_anm, front, text='0'), 153 'highscore': Text((500, 58), self.ascii_anm, front, text='0'),
153 'score': Text((500, 82), self.ascii_anm, front, text='0'), 154 'score': Text((500, 82), self.ascii_anm, front, text='0'),
154 'player': Counter((500, 122), front, front, script=16, value=0), 155 'player': Counter((500, 122), front, front, script=16, value=0),
170 Gauge((100, 24), front), # Gauge 171 Gauge((100, 24), front), # Gauge
171 Gauge((100, 24), front), # Spellcard gauge 172 Gauge((100, 24), front), # Spellcard gauge
172 ] 173 ]
173 for item in self.boss_items: 174 for item in self.boss_items:
174 item.sprite.allow_dest_offset = True #XXX 175 item.sprite.allow_dest_offset = True #XXX
176
177
178 def start_stage(self, game, stage):
179 self.game = game
180 if stage < 6:
181 text = 'STAGE %d' % stage
182 elif stage == 6:
183 text = 'FINAL STAGE'
184 elif stage == 7:
185 text = 'EXTRA STAGE'
186 self.level_start = [Text((16+384/2, 200), self.ascii_anm, text=text, align='center')] #TODO: find the exact location.
187 self.level_start[0].set_timeout(240, effect='fadeout', duration=60, start=120)
188 self.level_start[0].set_color('yellow')
189 #TODO: use the system text for the stage name, and the song name.
175 190
176 191
177 def set_boss_life(self): 192 def set_boss_life(self):
178 if not self.game.boss: 193 if not self.game.boss:
179 return 194 return