comparison pytouhou/ui/gamerunner.py @ 341:61caded6b4f5

Clean music playback API a little.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 04 Jul 2012 23:05:21 +0200
parents 4eca6130f118
children 94fdb6c782c1
comparison
equal deleted inserted replaced
340:39bc59953dfa 341:61caded6b4f5
23 GL_TEXTURE_2D, GL_BLEND, GL_FOG, 23 GL_TEXTURE_2D, GL_BLEND, GL_FOG,
24 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, 24 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST,
25 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY, 25 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY,
26 GL_SCISSOR_TEST) 26 GL_SCISSOR_TEST)
27 27
28 from pyglet.media import Player as MusicPlayer
29
30 from pytouhou.utils.helpers import get_logger 28 from pytouhou.utils.helpers import get_logger
31 29
32 from .gamerenderer import GameRenderer 30 from .gamerenderer import GameRenderer
31 from .music import MusicPlayer
33 32
34 33
35 logger = get_logger(__name__) 34 logger = get_logger(__name__)
36 35
37 36
52 self.load_game(game, background, replay) 51 self.load_game(game, background, replay)
53 52
54 self.clock = pyglet.clock.get_default() 53 self.clock = pyglet.clock.get_default()
55 54
56 55
57 def load_game(self, game=None, background=None, replay=None): 56 def load_game(self, game=None, background=None, bgms=None, replay=None):
58 GameRenderer.load_game(self, game, background) 57 GameRenderer.load_game(self, game, background)
59 self.replay_level = None 58 self.replay_level = None
60 if not replay or not replay.levels[game.stage-1]: 59 if not replay or not replay.levels[game.stage-1]:
61 self.keys = pyglet.window.key.KeyStateHandler() 60 self.keys = pyglet.window.key.KeyStateHandler()
62 self.push_handlers(self.keys) 61 self.push_handlers(self.keys)
63 else: 62 else:
64 self.keys = 0 63 self.keys = 0
65 self.replay_level = replay.levels[game.stage-1] 64 self.replay_level = replay.levels[game.stage-1]
66 self.game.players[0].state.lives = self.replay_level.lives 65 game.players[0].state.lives = self.replay_level.lives
67 self.game.players[0].state.power = self.replay_level.power 66 game.players[0].state.power = self.replay_level.power
68 self.game.players[0].state.bombs = self.replay_level.bombs 67 game.players[0].state.bombs = self.replay_level.bombs
69 self.game.difficulty = self.replay_level.difficulty 68 game.difficulty = self.replay_level.difficulty
69
70 game.music = MusicPlayer(game.resource_loader, bgms)
71 game.music.play(0)
70 72
71 73
72 def start(self, width=None, height=None): 74 def start(self, width=None, height=None):
73 width = width or (self.game.interface.width if self.game else 640) 75 width = width or (self.game.interface.width if self.game else 640)
74 height = height or (self.game.interface.height if self.game else 480) 76 height = height or (self.game.interface.height if self.game else 480)
82 glHint(GL_FOG_HINT, GL_NICEST) 84 glHint(GL_FOG_HINT, GL_NICEST)
83 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) 85 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
84 glEnableClientState(GL_COLOR_ARRAY) 86 glEnableClientState(GL_COLOR_ARRAY)
85 glEnableClientState(GL_VERTEX_ARRAY) 87 glEnableClientState(GL_VERTEX_ARRAY)
86 glEnableClientState(GL_TEXTURE_COORD_ARRAY) 88 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
87
88 # Initialize sound
89 self.game.music = MusicPlayer()
90 bgm = self.game.bgms[0]
91 if bgm:
92 self.game.music.queue(bgm)
93 self.game.music.play()
94 89
95 if self.fps_limit > 0: 90 if self.fps_limit > 0:
96 pyglet.clock.set_fps_limit(self.fps_limit) 91 pyglet.clock.set_fps_limit(self.fps_limit)
97 while not self.has_exit: 92 while not self.has_exit:
98 pyglet.clock.tick() 93 pyglet.clock.tick()