-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsounds.py
91 lines (77 loc) · 1.61 KB
/
sounds.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#
# Sound list
#
# FX:
# 0 - Death
# 1 - Checkpoint
# 2 - all Checkpoints
# 3..10: Player moves, random sound
# 11 - Player turn
# 12 - You Made it! synth
#
# Music: Total 7 songs
import pygame.mixer as MIXER
from random import randint
from mazeconfig import *
CURRSONG = -1
NSONGS = 9
FXON = True
MUSICON = True
MIXER.init()
#FX = [MIXER.Sound("fx/fx0.ogg")]
FX = []
for f in range(13):
fx = MIXER.Sound(getdatapath()+"fx/fx"+str(f)+".ogg")
FX.append(fx)
def toggle_fx():
global FXON
if FXON: FXON = False
else: FXON = True
return FXON
def toggle_music():
global MUSICON
if MUSICON:
MIXER.music.stop()
MUSICON = False
else:
MIXER.music.play()
MUSICON = True
return MUSICON
def play_fx(ids):
"""
Play a sound specified by id
if the sound exists, else do nothing
"""
if not FXON: return
try:
FX[ids].play()
except:
pass
def play_fx_player_rand():
"""
FUCKING BAD IDEA, sounds like HELL
Play a sound for the player when turning
random sounds of a scale
"""
try:
FX[randint(3,10)].play()
except:
pass
def play_music(index):
if not MUSICON: return
try:
MIXER.music.load(getdatapath()+"music/m"+str(index)+".ogg")
except:
MIXER.music.load(getdatapath()+"music/m"+str(index)+".ogg")
print "WARNING: unknow music index, loading default"
MIXER.music.play(-1)
def play_music_random():
if not MUSICON: return
index = -1
while index==CURRSONG:index = randint(1,NSONGS)
try:
MIXER.music.load(getdatapath()+"music/m"+str(index)+".ogg")
except:
MIXER.music.load(getdatapath()+"music/m"+str(index)+".ogg")
print "WARNING: unknow music index, loading default"
MIXER.music.play(-1)