forked from arda-guler/miniLanding3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.py
41 lines (32 loc) · 922 Bytes
/
sound.py
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
from pygame import mixer
import os
bgms = {}
def init_sound():
global bgms
mixer.init()
for bgm in os.listdir("data/bgm"):
newmsc = mixer.Sound("data/bgm/" + bgm)
bgms[bgm[:-4]] = newmsc
def play_sfx(track, loops=0, channel=1, volume=1):
chn = mixer.Channel(channel)
track_full = "data/sounds/" + str(track) + ".ogg"
snd = mixer.Sound(track_full)
chn.set_volume(volume)
chn.play(snd, loops)
def get_channel_busy(channel):
chn = mixer.Channel(channel)
return chn.get_busy()
def is_music_playing():
return get_channel_busy(7)
def set_channel_volume(channel, volume):
channel = mixer.Channel(channel)
channel.set_volume(volume)
def stop_channel(channel):
channel = mixer.Channel(channel)
channel.stop()
def play_bgm(track, channel=7):
global bgms
chn = mixer.Channel(7)
msc = bgms[track]
chn.set_volume(1)
chn.play(msc)