comparison skaapsteker/engine.py @ 262:de60329cfc9f

Factor out sound stuff
author Neil Muller <drnlmuller@gmail.com>
date Fri, 08 Apr 2011 11:29:37 +0200
parents 8d7edd77bfbf
children afd9256ad682
comparison
equal deleted inserted replaced
261:7668243695f4 262:de60329cfc9f
6 from pygame.locals import QUIT, USEREVENT 6 from pygame.locals import QUIT, USEREVENT
7 7
8 8
9 class Engine(object): 9 class Engine(object):
10 10
11 def __init__(self): 11 def __init__(self, soundsystem):
12 # avoid circular imports 12 # avoid circular imports
13 from .gamestate import GameState 13 from .gamestate import GameState
14 self._framerate = 60 14 self._framerate = 60
15 self._current_scene = None 15 self._current_scene = None
16 self._fpss = [self._framerate] * 100 16 self._fpss = [self._framerate] * 100
17 self._cur_frame = 0 17 self._cur_frame = 0
18 self.game_state = GameState("game.json") 18 self.game_state = GameState("game.json")
19 self.soundsystem = soundsystem
19 20
20 def change_scene(self, next_scene): 21 def change_scene(self, next_scene):
22 self.soundsystem.stop_music()
21 if self._current_scene is not None: 23 if self._current_scene is not None:
22 self._current_scene.leave() 24 self._current_scene.leave()
23 self._current_scene = next_scene 25 self._current_scene = next_scene
24 self._current_scene.enter() 26 self._current_scene.enter()
25 27
49 return sum(self._fpss) / 100 51 return sum(self._fpss) / 100
50 52
51 53
52 class Scene(object): 54 class Scene(object):
53 55
54 def __init__(self, game_state): 56 def __init__(self, game_state, soundsystem):
55 self.widgets = [] 57 self.widgets = []
56 self.game_state = game_state 58 self.game_state = game_state
59 self._soundsystem = soundsystem
57 60
58 def post(self, ev): 61 def post(self, ev):
59 """Post an event to pygame's event loop.""" 62 """Post an event to pygame's event loop."""
60 pygame.event.post(ev) 63 pygame.event.post(ev)
61 64