Deavid: Patch 1. Various improvements.
[lightyears.git] / code / sound.py
bloba89e54f610fe019d3d336381014ae894d1f28e8a
1 #
2 # 20,000 Light Years Into Space
3 # This game is licensed under GPL v2, and copyright (C) Jack Whitham 2006-07.
4 #
7 import pygame
8 from pygame.locals import *
10 import resource, time
12 last_time = 0
14 def FX(name):
15 global last_time
16 cur_time = time.time()
17 if (cur_time-last_time>1):
18 s = resource.Load_Sound(name) # (comes from a cache)
19 if ( s != None ):
20 s.play()
21 last_time=cur_time;
24 class Persisting_Sound:
25 def __init__(self, name, secondary=None):
26 self.sobj = resource.Load_Sound(name)
27 if ( secondary != None ):
28 # A different, less annoying mode.
29 self.sobj2 = resource.Load_Sound(secondary)
30 else:
31 self.sobj2 = self.sobj
33 self.schan = None
35 def Set(self, volume):
36 if (( self.sobj == None )
37 or ( self.sobj2 == None )):
38 return
40 if ( volume <= 0.0 ):
41 self.sobj.stop()
42 self.sobj2.stop()
43 else:
44 self.sobj.set_volume(volume)
45 self.sobj2.set_volume(volume)
46 if (( self.schan == None )
47 or ( not ( self.schan.get_sound()
48 in [ self.sobj , self.sobj2 ] ))):
49 self.schan = self.sobj.play()
51 self.schan.queue(self.sobj2)
53 def Fade_Out(self):
54 if (( self.sobj == None )
55 or ( self.sobj2 == None )
56 or ( self.schan == None )):
57 return
59 self.schan.queue(self.sobj2)
60 self.sobj2.fadeout(200)