source: trunk/game/scripts/sounds.py @ 415

Revision 313, 2.4 KB checked in by Kaydeth_parpg, 10 years ago (diff)

Ticket #2: Patch by Kaydeth. Updated the rest of the classes in the scripts directory to correct some obvious discrepancies with our coding standard. Still need to go through the common and objects sub directories. comment[s:trac, t:2]

  • Property svn:eol-style set to native
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        """Initialise the SoundEngine instance
23           @type fife_engine: fine.Engine
24           @param fife_engine: Instance of the Fife engine
25           @return: None"""
26        self.engine = fife_engine
27        self.sound_engine = self.engine.getSoundManager()
28        self.sound_engine.init()
29        # set up the sound
30        self.music = self.sound_engine.createEmitter()
31        self.music_on = False
32        self.music_init = False
33   
34    def playMusic(self, sfile=None):
35        """Play music, with the given file if passed
36           @type sfile: string
37           @param sfile: Filename to play
38           @return: None"""
39        if(sfile is not None):
40            # setup the new sound
41            sound = self.engine.getSoundClipPool().addResourceFromFile(sfile)
42            self.music.setSoundClip(sound)
43            self.music.setLooping(True)
44            self.music_init = True
45        self.music.play()
46        self.music_on = True
47
48    def pauseMusic(self):
49        """Stops current playback
50           @return: None"""
51        if(self.music_init == True):
52            self.music.pause()
53            self.music_on = False
54
55    def toggleMusic(self):
56        """Toggle status of music, either on or off
57           @return: None"""
58        if((self.music_on == False)and(self.music_init == True)):
59            self.playMusic()
60        else:
61            self.pauseMusic()
62
63    def setVolume(self, volume):
64        """Set the volume of the music
65           @type volume: integer
66           @param volume: The volume wanted, 0 to 100
67           @return: None"""
68        self.sound_engine.setVolume(0.01 * volume)
69
Note: See TracBrowser for help on using the repository browser.