comparison pytouhou/ui/gamerunner.py @ 475:9d4d52793eca

Experimental netplay! Yay!
author Thibaut Girka <thib@sitedethib.com>
date Wed, 28 Dec 2011 18:45:09 +0100
parents 2d35565b5608
children e71b1bcf952a
comparison
equal deleted inserted replaced
228:8f4cd1c01d22 475:9d4d52793eca
30 30
31 logger = get_logger(__name__) 31 logger = get_logger(__name__)
32 32
33 33
34 class GameRunner(pyglet.window.Window, GameRenderer): 34 class GameRunner(pyglet.window.Window, GameRenderer):
35 def __init__(self, resource_loader, game=None, background=None, replay=None): 35 def __init__(self, resource_loader, game=None, background=None, replay=None,
36 con=None):
36 GameRenderer.__init__(self, resource_loader, game, background) 37 GameRenderer.__init__(self, resource_loader, game, background)
37 38
38 width, height = (game.width, game.height) if game else (None, None) 39 width, height = (game.width, game.height) if game else (None, None)
39 pyglet.window.Window.__init__(self, width=width, height=height, 40 pyglet.window.Window.__init__(self, width=width, height=height,
40 caption='PyTouhou', resizable=False) 41 caption='PyTouhou', resizable=False)
41 42
43 self.con = con
42 self.replay_level = None 44 self.replay_level = None
43 if not replay or not replay.levels[game.stage-1]: 45 if not replay or not replay.levels[game.stage-1]:
44 self.keys = pyglet.window.key.KeyStateHandler() 46 self.keys = pyglet.window.key.KeyStateHandler()
45 self.push_handlers(self.keys) 47 self.push_handlers(self.keys)
46 else: 48 else:
123 keystate |= 64 125 keystate |= 64
124 if self.keys[pyglet.window.key.RIGHT]: 126 if self.keys[pyglet.window.key.RIGHT]:
125 keystate |= 128 127 keystate |= 128
126 if self.keys[pyglet.window.key.LCTRL]: 128 if self.keys[pyglet.window.key.LCTRL]:
127 keystate |= 256 129 keystate |= 256
128 self.game.run_iter(keystate)
129 else: 130 else:
130 keystate = 0 131 keystate = 0
131 for frame, _keystate, unknown in self.replay_level.keys: 132 for frame, _keystate, unknown in self.replay_level.keys:
132 if self.game.frame < frame: 133 if self.game.frame < frame:
133 break 134 break
134 else: 135 else:
135 keystate = _keystate 136 keystate = _keystate
136 137
137 self.game.run_iter(keystate) 138 if self.con:
139 self.con.run_iter(self.game, keystate)
140 else:
141 self.game.run_iter([keystate])
138 142
139 143
140 def on_draw(self): 144 def on_draw(self):
141 # Switch to game projection 145 # Switch to game projection
142 #TODO: move that to GameRenderer? 146 #TODO: move that to GameRenderer?