Mercurial > touhou
comparison pytouhou/ui/music.py @ 379:e0e284fcb288
Make a sound when an enemy is hit.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 30 Aug 2012 11:34:56 +0200 |
parents | 70e2ed71b09c |
children | d8aab27a2ab2 |
comparison
equal
deleted
inserted
replaced
378:11d895b6c0dc | 379:e0e284fcb288 |
---|---|
122 self.player.queue(bgm) | 122 self.player.queue(bgm) |
123 self.player.play() | 123 self.player.play() |
124 | 124 |
125 | 125 |
126 class SFXPlayer(object): | 126 class SFXPlayer(object): |
127 def __init__(self, loader): | 127 def __init__(self, loader, volume=.42): |
128 self.loader = loader | 128 self.loader = loader |
129 self.players = {} | |
129 self.sounds = {} | 130 self.sounds = {} |
130 | 131 self.volume = volume |
131 self.player = Player() | |
132 self.player.volume = .5 | |
133 | |
134 #'powerup.wav', 'graze.wav', 'timeout.wav', 'extend.wav', 'kira02.wav', 'kira01.wav', | |
135 #'kira00.wav', 'item00.wav', 'damage00.wav', 'nep00.wav', 'enep01.wav', 'lazer01.wav', | |
136 #'lazer00.wav', 'cat00.wav', 'gun00.wav', 'select00.wav', 'cancel00.wav', 'ok00.wav', | |
137 #'tan02.wav', 'tan01.wav', 'tan00.wav', 'power1.wav', 'power0.wav', 'pldead00.wav', | |
138 #'enep00.wav', 'plst00.wav')} | |
139 | 132 |
140 | 133 |
141 def __getitem__(self, name): | 134 def get_player(self, name): |
142 if not name in self.sounds: | 135 if name not in self.players: |
143 self.sounds[name] = self.load_sound(name) | 136 self.players[name] = Player() |
137 self.players[name].volume = self.volume | |
138 return self.players[name] | |
139 | |
140 | |
141 def get_sound(self, name): | |
142 if name not in self.sounds: | |
143 wave_file = self.loader.get_file(name) | |
144 self.sounds[name] = StaticSource(WaveSource(name, wave_file)) | |
144 return self.sounds[name] | 145 return self.sounds[name] |
145 | 146 |
146 | 147 |
147 def load_sound(self, name): | 148 def play(self, name, volume=None): |
148 file = self.loader.get_file(name) | 149 sound = self.get_sound(name) |
149 return StaticSource(WaveSource(name, file)) | 150 player = self.get_player(name) |
151 if volume: | |
152 player.volume = volume | |
153 if player.playing: | |
154 player.next() | |
155 if sound: | |
156 player.queue(sound) | |
157 player.play() | |
158 | |
159 | |
160 class NullPlayer(object): | |
161 def __init__(self, loader=None, bgms=None): | |
162 pass | |
163 | |
150 | 164 |
151 def play(self, name): | 165 def play(self, name): |
152 sound = self[name] | 166 pass |
153 if self.player.playing: | |
154 self.player.next() | |
155 if sound: | |
156 self.player.queue(sound) | |
157 self.player.play() | |
158 |