comparison pytouhou/ui/gamerunner.py @ 373:6deab6ad8be8

Add the ability to save a replay.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 05 Aug 2012 16:37:26 +0200
parents 74471afbac37
children 6a63fd3deb76
comparison
equal deleted inserted replaced
372:704bea2e4360 373:6deab6ad8be8
59 self.load_game(game, background, replay) 59 self.load_game(game, background, replay)
60 60
61 self.clock = pyglet.clock.get_default() 61 self.clock = pyglet.clock.get_default()
62 62
63 63
64 def load_game(self, game=None, background=None, bgms=None, replay=None): 64 def load_game(self, game=None, background=None, bgms=None, replay=None, save_keystates=None):
65 GameRenderer.load_game(self, game, background) 65 GameRenderer.load_game(self, game, background)
66 self.replay_level = None 66 self.replay_level = None
67 if not replay or not replay.levels[game.stage-1]: 67 if not replay or not replay.levels[game.stage-1]:
68 self.keys = pyglet.window.key.KeyStateHandler() 68 self.keys = pyglet.window.key.KeyStateHandler()
69 self.push_handlers(self.keys) 69 self.push_handlers(self.keys)
72 self.replay_level = replay.levels[game.stage-1] 72 self.replay_level = replay.levels[game.stage-1]
73 game.players[0].state.lives = self.replay_level.lives 73 game.players[0].state.lives = self.replay_level.lives
74 game.players[0].state.power = self.replay_level.power 74 game.players[0].state.power = self.replay_level.power
75 game.players[0].state.bombs = self.replay_level.bombs 75 game.players[0].state.bombs = self.replay_level.bombs
76 game.difficulty = self.replay_level.difficulty 76 game.difficulty = self.replay_level.difficulty
77
78 self.save_keystates = save_keystates
77 79
78 game.music = MusicPlayer(game.resource_loader, bgms) 80 game.music = MusicPlayer(game.resource_loader, bgms)
79 game.music.play(0) 81 game.music.play(0)
80 82
81 game.player_sfx = SFXPlayer(game.resource_loader) 83 game.player_sfx = SFXPlayer(game.resource_loader)
164 if self.game.frame < frame: 166 if self.game.frame < frame:
165 break 167 break
166 else: 168 else:
167 keystate = _keystate 169 keystate = _keystate
168 170
171 if self.save_keystates is not None:
172 self.save_keystates.append(keystate)
173
169 self.game.run_iter(keystate) 174 self.game.run_iter(keystate)
170 175
171 176
172 def render_game(self): 177 def render_game(self):
173 # Switch to game projection 178 # Switch to game projection