comparison pytouhou/ui/gamerunner.py @ 374:6a63fd3deb76

Use an iterator to get the keystates from a replay.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 05 Aug 2012 18:19:42 +0200
parents 6deab6ad8be8
children 11d895b6c0dc
comparison
equal deleted inserted replaced
373:6deab6ad8be8 374:6a63fd3deb76
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)
70 else: 70 else:
71 self.keys = 0
72 self.replay_level = replay.levels[game.stage-1] 71 self.replay_level = replay.levels[game.stage-1]
72 self.keys = self.replay_level.iter_keystates()
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 77
159 if self.keys[pyglet.window.key.RIGHT]: 159 if self.keys[pyglet.window.key.RIGHT]:
160 keystate |= 128 160 keystate |= 128
161 if self.keys[pyglet.window.key.LCTRL]: 161 if self.keys[pyglet.window.key.LCTRL]:
162 keystate |= 256 162 keystate |= 256
163 else: 163 else:
164 keystate = 0 164 try:
165 for frame, _keystate, unknown in self.replay_level.keys: 165 keystate = self.keys.next()
166 if self.game.frame < frame: 166 except StopIteration:
167 break 167 keystate = 0
168 else:
169 keystate = _keystate
170 168
171 if self.save_keystates is not None: 169 if self.save_keystates is not None:
172 self.save_keystates.append(keystate) 170 self.save_keystates.append(keystate)
173 171
174 self.game.run_iter(keystate) 172 self.game.run_iter(keystate)