source: trunk/PARPG/scripts/sounds.py @ 135

Revision 135, 1.6 KB checked in by maximinus_parpg, 11 years ago (diff)

Added 'm' button to toggle music on/off.
Updated README file.

Line 
1#!/usr/bin/python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18# sounds.py holds the object code to play sounds and sound effects
19
20class SoundEngine:
21    def __init__(self, fife_engine):
22        self.engine = fife_engine
23        self.sound_engine = self.engine.getSoundManager()
24        self.sound_engine.init()
25        # set up the sound
26        self.music = self.sound_engine.createEmitter()
27        self.music_on = False
28   
29    def playMusic(self, sfile = None):
30        if(sfile != None):
31            # setup the new sound
32            sound = self.engine.getSoundClipPool().addResourceFromFile(sfile)
33            self.music.setSoundClip(sound)
34            self.music.setLooping(True)
35        self.music.play()
36        self.music_on = True
37   
38    def pauseMusic(self):
39        """Stop current playback"""
40        self.music.pause()
41        self.music_on = False
42
43    def toggleMusic(self):
44        if(self.music_on == False):
45            self.playMusic()
46        else:
47            self.pauseMusic()
48
49    def setVolume(self, volume):
50        pass
51
Note: See TracBrowser for help on using the repository browser.