Mercurial > boomslang
annotate gamelib/sound.py @ 114:13d8cb1d5962
Better cursor handling using draw_all() and mouse_delta().
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Tue, 24 Aug 2010 14:51:22 +0200 |
parents | 18ffaaaa27e7 |
children | 3b293e3b8829 |
rev | line source |
---|---|
107 | 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 | |
111
18ffaaaa27e7
Add explicit check for sound file existence (my pygame 1.9 returns a valid sound object even when the path does not exist).
Simon Cross <simon@simonx>
parents:
107
diff
changeset
|
7 import os |
18ffaaaa27e7
Add explicit check for sound file existence (my pygame 1.9 returns a valid sound object even when the path does not exist).
Simon Cross <simon@simonx>
parents:
107
diff
changeset
|
8 |
107 | 9 from albow.resource import _resource_path, dummy_sound |
10 | |
11 sound_cache = {} | |
12 | |
13 def get_sound(*names): | |
14 if sound_cache is None: | |
15 return dummy_sound | |
16 path = _resource_path("sounds", names) | |
17 sound = sound_cache.get(path) | |
18 if not sound: | |
111
18ffaaaa27e7
Add explicit check for sound file existence (my pygame 1.9 returns a valid sound object even when the path does not exist).
Simon Cross <simon@simonx>
parents:
107
diff
changeset
|
19 if not os.path.isfile(path): |
18ffaaaa27e7
Add explicit check for sound file existence (my pygame 1.9 returns a valid sound object even when the path does not exist).
Simon Cross <simon@simonx>
parents:
107
diff
changeset
|
20 missing_sound("File does not exist", path) |
18ffaaaa27e7
Add explicit check for sound file existence (my pygame 1.9 returns a valid sound object even when the path does not exist).
Simon Cross <simon@simonx>
parents:
107
diff
changeset
|
21 return dummy_sound |
107 | 22 try: |
23 from pygame.mixer import Sound | |
24 except ImportError, e: | |
25 no_sound(e) | |
26 return dummy_sound | |
27 try: | |
28 sound = Sound(path) | |
29 except pygame.error, e: | |
30 missing_sound(e, path) | |
31 return dummy_sound | |
32 sound_cache[path] = sound | |
33 return sound | |
34 | |
35 | |
36 def no_sound(e): | |
37 global sound_cache | |
38 print "get_sound: %s" % e | |
39 print "get_sound: Sound not available, continuing without it" | |
40 sound_cache = None | |
41 | |
42 def disable_sound(): | |
43 global sound_cache | |
44 sound_cache = None | |
45 | |
46 def missing_sound(e, name): | |
47 print "albow.resource.get_sound: %s: %s" % (name, e) | |
48 |