Mercurial > parpg-source
comparison sounds.py @ 0:7a89ea5404b1
Initial commit of parpg-core.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 14 May 2011 01:12:35 -0700 |
parents | |
children | 80672955ab70 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7a89ea5404b1 |
---|---|
1 # This file is part of PARPG. | |
2 | |
3 # PARPG is free software: you can redistribute it and/or modify | |
4 # it under the terms of the GNU General Public License as published by | |
5 # the Free Software Foundation, either version 3 of the License, or | |
6 # (at your option) any later version. | |
7 | |
8 # PARPG is distributed in the hope that it will be useful, | |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 # GNU General Public License for more details. | |
12 | |
13 # You should have received a copy of the GNU General Public License | |
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. | |
15 | |
16 # sounds.py holds the object code to play sounds and sound effects | |
17 | |
18 class SoundEngine: | |
19 def __init__(self, fife_engine): | |
20 """Initialise the SoundEngine instance | |
21 @type fife_engine: fine.Engine | |
22 @param fife_engine: Instance of the Fife engine | |
23 @return: None""" | |
24 self.engine = fife_engine | |
25 self.sound_engine = self.engine.getSoundManager() | |
26 self.sound_engine.init() | |
27 # set up the sound | |
28 self.music = self.sound_engine.createEmitter() | |
29 self.music_on = False | |
30 self.music_init = False | |
31 | |
32 def playMusic(self, sfile=None): | |
33 """Play music, with the given file if passed | |
34 @type sfile: string | |
35 @param sfile: Filename to play | |
36 @return: None""" | |
37 if(sfile is not None): | |
38 # setup the new sound | |
39 sound = self.engine.getSoundClipPool().addResourceFromFile(sfile) | |
40 self.music.setSoundClip(sound) | |
41 self.music.setLooping(True) | |
42 self.music_init = True | |
43 self.music.play() | |
44 self.music_on = True | |
45 | |
46 def pauseMusic(self): | |
47 """Stops current playback | |
48 @return: None""" | |
49 if(self.music_init == True): | |
50 self.music.pause() | |
51 self.music_on = False | |
52 | |
53 def toggleMusic(self): | |
54 """Toggle status of music, either on or off | |
55 @return: None""" | |
56 if((self.music_on == False)and(self.music_init == True)): | |
57 self.playMusic() | |
58 else: | |
59 self.pauseMusic() | |
60 | |
61 def setVolume(self, volume): | |
62 """Set the volume of the music | |
63 @type volume: integer | |
64 @param volume: The volume wanted, 0 to 100 | |
65 @return: None""" | |
66 self.sound_engine.setVolume(0.01 * volume) | |
67 |