comparison pytouhou/games/eosd.py @ 494:6be9c99a3a24

Merge PlayerState into Player, fix player respawn position.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 14 Oct 2013 12:11:01 +0200
parents 887de1309491
children c622eaf64428
comparison
equal deleted inserted replaced
493:26c082870dcf 494:6be9c99a3a24
26 26
27 from pytouhou.vm.eclrunner import ECLMainRunner 27 from pytouhou.vm.eclrunner import ECLMainRunner
28 28
29 29
30 class EoSDCommon(object): 30 class EoSDCommon(object):
31 def __init__(self, resource_loader, player_state): 31 def __init__(self, resource_loader, player_characters, continues, stage):
32 self.etama = resource_loader.get_multi_anm(('etama3.anm', 'etama4.anm')) 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, 33 self.bullet_types = [BulletType(self.etama[0], 0, 11, 14, 15, 16, hitbox_size=2,
34 type_id=0), 34 type_id=0),
35 BulletType(self.etama[0], 1, 12, 17, 18, 19, hitbox_size=3, 35 BulletType(self.etama[0], 1, 12, 17, 18, 19, hitbox_size=3,
36 type_id=1), 36 type_id=1),
72 ('face08a.anm', 'face08b.anm'), 72 ('face08a.anm', 'face08b.anm'),
73 ('face09a.anm', 'face09b.anm'), 73 ('face09a.anm', 'face09b.anm'),
74 ('face09b.anm', 'face10a.anm', 'face10b.anm'), 74 ('face09b.anm', 'face10a.anm', 'face10b.anm'),
75 ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')] 75 ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')]
76 76
77 self.characters = resource_loader.get_eosd_characters() 77 default_power = [0, 64, 128, 128, 128, 128, 0][stage]
78 self.interface = EoSDInterface(resource_loader, player_state) 78
79 eosd_characters = resource_loader.get_eosd_characters()
80 self.first_character = player_characters[0] // 2
81 self.player_anms = {}
82 self.players = [None] * len(player_characters)
83 for i, player_character in enumerate(player_characters):
84 character = player_character // 2
85 if character not in self.player_anms:
86 face = resource_loader.get_multi_anm(('face0%da.anm' % character,
87 'face0%db.anm' % character,
88 'face0%dc.anm' % character))
89 anm = resource_loader.get_single_anm('player0%d.anm' % character)
90 self.player_anms[character] = (anm, face)
91
92 self.players[i] = EoSDPlayer(i, self.player_anms[character][0],
93 eosd_characters[player_character],
94 character, default_power, continues)
95
96 self.interface = EoSDInterface(resource_loader, self.players[0]) #XXX
79 97
80 98
81 99
82 class EoSDGame(Game): 100 class EoSDGame(Game):
83 def __init__(self, resource_loader, player_states, stage, rank, difficulty, 101 def __init__(self, resource_loader, stage, rank, difficulty,
84 common, nb_bullets_max=640, width=384, height=448, prng=None, 102 common, nb_bullets_max=640, width=384, height=448, prng=None,
85 hints=None, friendly_fire=True): 103 hints=None, friendly_fire=True):
86 104
87 self.etama = common.etama #XXX 105 self.etama = common.etama #XXX
88 try: 106 try:
93 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage) 111 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
94 self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains] 112 self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains]
95 113
96 self.spellcard_effect_anm = resource_loader.get_single_anm('eff0%d.anm' % stage) 114 self.spellcard_effect_anm = resource_loader.get_single_anm('eff0%d.anm' % stage)
97 115
98 player_face = player_states[0].character // 2
99 self.msg = resource_loader.get_msg('msg%d.dat' % stage) 116 self.msg = resource_loader.get_msg('msg%d.dat' % stage)
100 msg_anm = [resource_loader.get_multi_anm(('face0%da.anm' % player_face, 117 msg_anm = [common.player_anms[common.first_character][1], #TODO: does it break bomb face of non-first player?
101 'face0%db.anm' % player_face,
102 'face0%dc.anm' % player_face)),
103 resource_loader.get_multi_anm(common.enemy_face[stage - 1])] 118 resource_loader.get_multi_anm(common.enemy_face[stage - 1])]
104 119
105 self.msg_anm = [[], []] 120 self.msg_anm = [[], []]
106 for i, anms in enumerate(msg_anm): 121 for i, anms in enumerate(msg_anm):
107 for anm in anms: 122 for anm in anms:
108 for sprite in anm.sprites.values(): 123 for sprite in anm.sprites.values():
109 self.msg_anm[i].append((anm, sprite)) 124 self.msg_anm[i].append((anm, sprite))
110 125
111 players = [EoSDPlayer(state, self, resource_loader, common.characters[state.character]) for state in player_states] 126 for player in common.players:
127 player._game = self
112 128
113 # Load stage data 129 # Load stage data
114 self.std = resource_loader.get_stage('stage%d.std' % stage) 130 self.std = resource_loader.get_stage('stage%d.std' % stage)
115 131
116 background_anm = resource_loader.get_single_anm('stg%dbg.anm' % stage) 132 background_anm = resource_loader.get_single_anm('stg%dbg.anm' % stage)
119 common.interface.start_stage(self, stage) 135 common.interface.start_stage(self, stage)
120 self.native_texts = [common.interface.stage_name, common.interface.song_name] 136 self.native_texts = [common.interface.stage_name, common.interface.song_name]
121 137
122 self.resource_loader = resource_loader #XXX: currently used for texture preload in pytouhou.ui.gamerunner. Wipe it! 138 self.resource_loader = resource_loader #XXX: currently used for texture preload in pytouhou.ui.gamerunner. Wipe it!
123 139
124 Game.__init__(self, players, stage, rank, difficulty, 140 Game.__init__(self, common.players, stage, rank, difficulty,
125 common.bullet_types, common.laser_types, 141 common.bullet_types, common.laser_types,
126 common.item_types, nb_bullets_max, width, height, prng, 142 common.item_types, nb_bullets_max, width, height, prng,
127 common.interface, hints, friendly_fire) 143 common.interface, hints, friendly_fire)
128 144
129 145
142 self.highscore = 1000000 #TODO: read score.dat 158 self.highscore = 1000000 #TODO: read score.dat
143 self.items = ([Effect((0, 32 * i), 6, front) for i in range(15)] + 159 self.items = ([Effect((0, 32 * i), 6, front) for i in range(15)] +
144 [Effect((416 + 32 * i, 32 * j), 6, front) for i in range(7) for j in range(15)] + 160 [Effect((416 + 32 * i, 32 * j), 6, front) for i in range(7) for j in range(15)] +
145 [Effect((32 + 32 * i, 0), 7, front) for i in range(12)] + 161 [Effect((32 + 32 * i, 0), 7, front) for i in range(12)] +
146 [Effect((32 + 32 * i, 464), 8, front) for i in range(12)] + 162 [Effect((32 + 32 * i, 464), 8, front) for i in range(12)] +
147 [Effect((0, 0), 5, front)] + 163 [Effect((0, 0), i, front) for i in reversed(range(6))] +
148 [Effect((0, 0), i, front) for i in range(5) + range(9, 16)]) 164 [Effect((0, 0), i, front) for i in range(9, 16)])
149 for item in self.items: 165 for item in self.items:
150 item.sprite.allow_dest_offset = True #XXX 166 item.sprite.allow_dest_offset = True #XXX
151 167
152 self.level_start = [] 168 self.level_start = []
153 169
267 timeout_label.changed = True 283 timeout_label.changed = True
268 284
269 285
270 286
271 class EoSDPlayer(Player): 287 class EoSDPlayer(Player):
272 def __init__(self, state, game, resource_loader, character): 288 def __init__(self, number, anm, shts, character, power, continues):
273 self.sht = character[0] 289 self.sht = shts[0]
274 self.focused_sht = character[1] 290 self.focused_sht = shts[1]
275 self.anm = resource_loader.get_single_anm('player0%d.anm' % (state.character // 2)) 291
276 292 Player.__init__(self, number, anm, character, power, continues)
277 Player.__init__(self, state, game, self.anm) 293
278 294 self.orbs = [Orb(anm, 128, self),
279 self.orbs = [Orb(self.anm, 128, self.state), 295 Orb(anm, 129, self)]
280 Orb(self.anm, 129, self.state)]
281 296
282 self.orbs[0].offset_x = -24 297 self.orbs[0].offset_x = -24
283 self.orbs[1].offset_x = 24 298 self.orbs[1].offset_x = 24
284 299
285 self.orb_dx_interpolator = None 300 self.orb_dx_interpolator = None
290 self.orb_dx_interpolator = Interpolator((24,), self._game.frame, 305 self.orb_dx_interpolator = Interpolator((24,), self._game.frame,
291 (8,), self._game.frame + 8, 306 (8,), self._game.frame + 8,
292 lambda x: x ** 2) 307 lambda x: x ** 2)
293 self.orb_dy_interpolator = Interpolator((0,), self._game.frame, 308 self.orb_dy_interpolator = Interpolator((0,), self._game.frame,
294 (-32,), self._game.frame + 8) 309 (-32,), self._game.frame + 8)
295 self.state.focused = True 310 self.focused = True
296 311
297 312
298 def stop_focusing(self): 313 def stop_focusing(self):
299 self.orb_dx_interpolator = Interpolator((8,), self._game.frame, 314 self.orb_dx_interpolator = Interpolator((8,), self._game.frame,
300 (24,), self._game.frame + 8, 315 (24,), self._game.frame + 8,
301 lambda x: x ** 2) 316 lambda x: x ** 2)
302 self.orb_dy_interpolator = Interpolator((-32,), self._game.frame, 317 self.orb_dy_interpolator = Interpolator((-32,), self._game.frame,
303 (0,), self._game.frame + 8) 318 (0,), self._game.frame + 8)
304 self.state.focused = False 319 self.focused = False
305 320
306 321
307 @property 322 @property
308 def objects(self): 323 def objects(self):
309 return [self] + (self.orbs if self.state.power >= 8 else []) 324 return [self] + (self.orbs if self.power >= 8 else [])
310 325
311 326
312 def update(self, keystate): 327 def update(self, keystate):
313 Player.update(self, keystate) 328 Player.update(self, keystate)
314 329