Mercurial > touhou
comparison pytouhou/ui/music.py @ 343:94fdb6c782c1
Implement sfx for player and enemies.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 04 Jul 2012 23:41:28 +0200 |
parents | 83c9354ff3ef |
children | f305cdd6f6c5 |
comparison
equal
deleted
inserted
replaced
342:83c9354ff3ef | 343:94fdb6c782c1 |
---|---|
13 ## | 13 ## |
14 | 14 |
15 | 15 |
16 from os.path import join | 16 from os.path import join |
17 | 17 |
18 from pyglet.media import AudioData, AudioFormat, Player | 18 from pyglet.media import AudioData, AudioFormat, StaticSource, Player |
19 from pyglet.media.riff import WaveSource | 19 from pyglet.media.riff import WaveSource |
20 | 20 |
21 | 21 |
22 class InfiniteWaveSource(WaveSource): | 22 class InfiniteWaveSource(WaveSource): |
23 def __init__(self, filename, start, end, file=None): | 23 def __init__(self, filename, start, end, file=None): |
110 self.player.next() | 110 self.player.next() |
111 if bgm: | 111 if bgm: |
112 self.player.queue(bgm) | 112 self.player.queue(bgm) |
113 self.player.play() | 113 self.player.play() |
114 | 114 |
115 | |
116 class SFXPlayer(object): | |
117 def __init__(self, loader): | |
118 self.loader = loader | |
119 self.sounds = {} | |
120 | |
121 self.player = Player() | |
122 self.player.volume = .5 | |
123 | |
124 #'powerup.wav', 'graze.wav', 'timeout.wav', 'extend.wav', 'kira02.wav', 'kira01.wav', | |
125 #'kira00.wav', 'item00.wav', 'damage00.wav', 'nep00.wav', 'enep01.wav', 'lazer01.wav', | |
126 #'lazer00.wav', 'cat00.wav', 'gun00.wav', 'select00.wav', 'cancel00.wav', 'ok00.wav', | |
127 #'tan02.wav', 'tan01.wav', 'tan00.wav', 'power1.wav', 'power0.wav', 'pldead00.wav', | |
128 #'enep00.wav', 'plst00.wav')} | |
129 | |
130 | |
131 def __getitem__(self, name): | |
132 if not name in self.sounds: | |
133 self.sounds[name] = self.load_sound(name) | |
134 return self.sounds[name] | |
135 | |
136 | |
137 def load_sound(self, name): | |
138 file = self.loader.get_file(name) | |
139 return StaticSource(WaveSource(name, file)) | |
140 | |
141 def play(self, name): | |
142 sound = self[name] | |
143 if self.player.playing: | |
144 self.player.next() | |
145 if sound: | |
146 self.player.queue(sound) | |
147 self.player.play() | |
148 |