Mercurial > boomslang
comparison pyntnclick/main.py @ 564:2f7aa3cad77c pyntnclick
Sound hackery
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sat, 11 Feb 2012 15:35:06 +0200 |
parents | 28f03563f4db |
children | aae75f7ce7a1 |
comparison
equal
deleted
inserted
replaced
563:18396b937647 | 564:2f7aa3cad77c |
---|---|
18 | 18 |
19 from pyntnclick.menu import MenuScreen | 19 from pyntnclick.menu import MenuScreen |
20 from pyntnclick.gamescreen import GameScreen | 20 from pyntnclick.gamescreen import GameScreen |
21 from pyntnclick.endscreen import EndScreen | 21 from pyntnclick.endscreen import EndScreen |
22 from pyntnclick.constants import ( | 22 from pyntnclick.constants import ( |
23 SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG) | 23 SCREEN, FRAME_RATE) |
24 from pyntnclick.sound import no_sound, disable_sound | 24 from pyntnclick.sound import Sound |
25 from pyntnclick import state, data | 25 from pyntnclick import state, data |
26 | 26 |
27 | 27 |
28 class MainShell(Shell): | 28 class MainShell(Shell): |
29 def __init__(self, display, initial_state): | 29 def __init__(self, display, initial_state): |
55 " of scenes.") | 55 " of scenes.") |
56 self._initial_scene = self.INITIAL_SCENE | 56 self._initial_scene = self.INITIAL_SCENE |
57 self._scene_list = self.SCENE_LIST | 57 self._scene_list = self.SCENE_LIST |
58 self._debug_rects = False | 58 self._debug_rects = False |
59 # TODO: make these real objects | 59 # TODO: make these real objects |
60 self.sound = object() | |
61 self.resource = object() | 60 self.resource = object() |
61 self.sound = Sound(self.resource) | |
62 | 62 |
63 def initial_state(self): | 63 def initial_state(self): |
64 """Create a copy of the initial game state.""" | 64 """Create a copy of the initial game state.""" |
65 initial_state = state.GameState(self) | 65 initial_state = state.GameState(self) |
66 initial_state.set_debug_rects(self._debug_rects) | 66 initial_state.set_debug_rects(self._debug_rects) |
85 parser = self.option_parser() | 85 parser = self.option_parser() |
86 opts, _ = parser.parse_args(sys.argv) | 86 opts, _ = parser.parse_args(sys.argv) |
87 pygame.display.init() | 87 pygame.display.init() |
88 pygame.font.init() | 88 pygame.font.init() |
89 if opts.sound: | 89 if opts.sound: |
90 try: | 90 self.sound.enable_sound() |
91 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) | |
92 except pygame.error, exc: | |
93 no_sound(exc) | |
94 else: | 91 else: |
95 # Ensure get_sound returns nothing, so everything else just works | 92 self.sound.disable_sound() |
96 disable_sound() | |
97 if DEBUG: | 93 if DEBUG: |
98 if opts.scene is not None: | 94 if opts.scene is not None: |
99 # debug the specified scene | 95 # debug the specified scene |
100 self._initial_scene = opts.scene | 96 self._initial_scene = opts.scene |
101 self._debug_rects = opts.rects | 97 self._debug_rects = opts.rects |