- try catch for soundless people :D

master
Steve Clement 2014-08-30 22:02:08 +02:00
parent 0557712ed4
commit c81bcc0974
2 changed files with 18 additions and 4 deletions

View File

@ -5,7 +5,7 @@ from support import operations
class Avocado:
def __init__(self, screen, color, size, select, filename='img/AvoCado_0.png'):
def __init__(self, screen, color, size, select, sound=True, filename='img/AvoCado_0.png'):
# We randomly decide whether we should instanciate or not
if random.randint(0,1) == 0:
self.is_falling = False
@ -81,12 +81,16 @@ class Avocado:
return True
def mute(self,mute=False):
if not sound:
return
if mute:
pygame.mixer.music.set_volume(0.0)
else:
pygame.mixer.music.set_volume(0.5)
def playLevel(self,lvl=1):
if not sound:
return
if lvl == 1:
pygame.mixer.music.load("""audio/level1.wav""")
elif lvl == 2:
@ -96,8 +100,12 @@ class Avocado:
pygame.mixer.music.play()
def fade(self):
if not sound:
return
pygame.mixer.music.fadeout(3000)
def loadClick(self):
if not sound:
return
self.click = pygame.mixer.Sound("audio/click.wav")
return self.click

12
game.py
View File

@ -21,8 +21,14 @@ def initialize_screen():
def main():
pygame.init()
pygame.mixer.init()
pygame.mixer.music.set_volume(0.5)
try:
pygame.mixer.init()
pygame.mixer.music.set_volume(0.5)
noSound = False
except:
print("Setting no sound :(")
noSound = True
pygame.display.set_caption('Pin Avo, the Cado!')
clock = pygame.time.Clock()
@ -92,7 +98,7 @@ def main():
for i in range(avocados_in_game, level):
avocolor = colors[random.randint(0, 3)]
avosize = (50, 50) # should we randomize this?
a = avocado.Avocado(screen, avocolor, avosize, color)
a = avocado.Avocado(screen, avocolor, avosize, color, noSound)
avocados.append(a)
avocados[:] = [ x for x in avocados if x.exists() ]