From c81bcc0974354ec36cce8a69a759caf82b804360 Mon Sep 17 00:00:00 2001 From: Steve Clement Date: Sat, 30 Aug 2014 22:02:08 +0200 Subject: [PATCH] - try catch for soundless people :D --- avocado.py | 10 +++++++++- game.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/avocado.py b/avocado.py index 9068128..25ac99d 100644 --- a/avocado.py +++ b/avocado.py @@ -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 diff --git a/game.py b/game.py index 8872bde..a9e9b9a 100755 --- a/game.py +++ b/game.py @@ -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() ]