Mercurial > pyntnclick
comparison gamelib/sound.py @ 107:5213b45fcc7e
Initial event sound support
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 24 Aug 2010 14:07:07 +0200 |
parents | |
children | 18ffaaaa27e7 |
comparison
equal
deleted
inserted
replaced
106:da547e148532 | 107:5213b45fcc7e |
---|---|
1 # Sound management for Suspended Sentence | |
2 | |
3 # This re-implements some of the albow.resource code to | |
4 # a) work around an annoying bugs | |
5 # b) add some missing functionality (disable_sound) | |
6 | |
7 from albow.resource import _resource_path, dummy_sound | |
8 | |
9 sound_cache = {} | |
10 | |
11 def get_sound(*names): | |
12 if sound_cache is None: | |
13 return dummy_sound | |
14 path = _resource_path("sounds", names) | |
15 sound = sound_cache.get(path) | |
16 if not sound: | |
17 try: | |
18 from pygame.mixer import Sound | |
19 except ImportError, e: | |
20 no_sound(e) | |
21 return dummy_sound | |
22 try: | |
23 sound = Sound(path) | |
24 except pygame.error, e: | |
25 missing_sound(e, path) | |
26 return dummy_sound | |
27 sound_cache[path] = sound | |
28 return sound | |
29 | |
30 | |
31 def no_sound(e): | |
32 global sound_cache | |
33 print "get_sound: %s" % e | |
34 print "get_sound: Sound not available, continuing without it" | |
35 sound_cache = None | |
36 | |
37 def disable_sound(): | |
38 global sound_cache | |
39 sound_cache = None | |
40 | |
41 def missing_sound(e, name): | |
42 print "albow.resource.get_sound: %s: %s" % (name, e) | |
43 |