-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sound.py
executable file
·74 lines (57 loc) · 2.25 KB
/
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
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
import pygame
import os
# Globals
global placeSound, forcedSound, badplaceSound
global badmoveSound, gameoverSound, removedSound, gothighSound
global soundEnabled
# The rest
def initSound():
"""Prepare the sound system by loading sounds and whatnot."""
global placeSound, forcedSound, badplaceSound
global badmoveSound, gameoverSound, removedSound, gothighSound
global soundEnabled
soundEnabled = False
# Load up all our sounds
placeSound = pygame.mixer.Sound(os.path.join("sounds", "place.wav"))
forcedSound = pygame.mixer.Sound(os.path.join("sounds", "forced.wav"))
badplaceSound = pygame.mixer.Sound(os.path.join("sounds", "badplace.wav"))
badmoveSound = pygame.mixer.Sound(os.path.join("sounds", "badmove.wav"))
gameoverSound = pygame.mixer.Sound(os.path.join("sounds", "gameover.wav"))
removedSound = pygame.mixer.Sound(os.path.join("sounds", "removed.wav"))
gothighSound = pygame.mixer.Sound(os.path.join("sounds", "gothigh.wav"))
# Did it work?
if ((placeSound != None) or (forcedSound != None) or
(badplaceSound != None) or (badmoveSound != None) or
(gameoverSound != None) or (removedSound != None) or
(gothighSound != None)):
soundEnabled = True
else:
print "Unable to load all sound files, sound disabled."
def playSound(theSound):
"""Play the sound for the given action"""
global placeSound, forcedSound, badplaceSound
global badmoveSound, gameoverSound, removedSound, gothighSound
global soundEnabled
if soundEnabled == False:
return
if theSound == "Place":
placeSound.play()
elif theSound == "Forced":
forcedSound.play()
elif theSound == "Bad Place":
badplaceSound.play()
elif theSound == "Bad Move":
badmoveSound.play()
elif theSound == "Game Over":
gameoverSound.play()
elif theSound == "Removed":
removedSound.play()
elif theSound == "Got High":
gothighSound.play()
else:
print "Unable to play sound, unknown sound \"%s\"" % (theSound)
def stopAll():
"""Stop playing all sounds"""
global soundEnabled
if soundEnabled:
pygame.mixer.stop()