File: sound.py

package info (click to toggle)
lightyears 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 1,324 kB
  • ctags: 454
  • sloc: python: 3,499; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,500 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 
# 20,000 Light Years Into Space
# This game is licensed under GPL v2, and copyright (C) Jack Whitham 2006-07.
# 


import pygame 
from pygame.locals import *

import resource, config



def FX(name):
    s = resource.Load_Sound(name) # (comes from a cache)
    if ( s != None ) and not config.cfg.mute:
        s.play()


class Persisting_Sound:
    def __init__(self, name, secondary=None):
        self.sobj = resource.Load_Sound(name)
        if ( secondary != None ):
            # A different, less annoying mode.
            self.sobj2 = resource.Load_Sound(secondary)
        else: 
            self.sobj2 = self.sobj

        self.schan = None

    def Set(self, volume):
        if (( self.sobj == None )
        or ( self.sobj2 == None )):
            return

        if config.cfg.mute:
            volume = 0.0

        if ( volume <= 0.0 ):
            self.sobj.stop()
            self.sobj2.stop()
        else:
            self.sobj.set_volume(volume)
            self.sobj2.set_volume(volume)
            if (( self.schan == None )
            or ( not ( self.schan.get_sound() 
                            in [ self.sobj , self.sobj2 ] ))):
                self.schan = self.sobj.play()
            if self.schan:
                self.schan.queue(self.sobj2)

    def Fade_Out(self):
        if (( self.sobj == None )
        or ( self.sobj2 == None )
        or ( self.schan == None )):
            return

        self.schan.queue(self.sobj2)
        self.sobj2.fadeout(200)