source: branches/active/character_customization/game/parpg/sounds.py @ 833

Revision 774, 2.4 KB checked in by aspidites, 9 years ago (diff)

Patch by Aspidites

  • removed shebang from all python files except launcher scripts
  • added shebang to pychan_designer
  • Property svn:eol-style set to native
RevLine 
[134]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
18class SoundEngine:
19    def __init__(self, fife_engine):
[141]20        """Initialise the SoundEngine instance
21           @type fife_engine: fine.Engine
22           @param fife_engine: Instance of the Fife engine
23           @return: None"""
[134]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()
[135]29        self.music_on = False
[140]30        self.music_init = False
[134]31   
[313]32    def playMusic(self, sfile=None):
[141]33        """Play music, with the given file if passed
34           @type sfile: string
35           @param sfile: Filename to play
36           @return: None"""
[313]37        if(sfile is not None):
[134]38            # setup the new sound
39            sound = self.engine.getSoundClipPool().addResourceFromFile(sfile)
40            self.music.setSoundClip(sound)
41            self.music.setLooping(True)
[140]42            self.music_init = True
[134]43        self.music.play()
[135]44        self.music_on = True
[140]45
[134]46    def pauseMusic(self):
[141]47        """Stops current playback
48           @return: None"""
[140]49        if(self.music_init == True):
50            self.music.pause()
51            self.music_on = False
[134]52
[135]53    def toggleMusic(self):
[141]54        """Toggle status of music, either on or off
55           @return: None"""
[140]56        if((self.music_on == False)and(self.music_init == True)):
[135]57            self.playMusic()
58        else:
59            self.pauseMusic()
60
[134]61    def setVolume(self, volume):
[141]62        """Set the volume of the music
63           @type volume: integer
64           @param volume: The volume wanted, 0 to 100
65           @return: None"""
[313]66        self.sound_engine.setVolume(0.01 * volume)
[134]67
Note: See TracBrowser for help on using the repository browser.