- try catch for soundless people :D
parent
0557712ed4
commit
c81bcc0974
10
avocado.py
10
avocado.py
|
@ -5,7 +5,7 @@ from support import operations
|
||||||
|
|
||||||
class Avocado:
|
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
|
# We randomly decide whether we should instanciate or not
|
||||||
if random.randint(0,1) == 0:
|
if random.randint(0,1) == 0:
|
||||||
self.is_falling = False
|
self.is_falling = False
|
||||||
|
@ -81,12 +81,16 @@ class Avocado:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def mute(self,mute=False):
|
def mute(self,mute=False):
|
||||||
|
if not sound:
|
||||||
|
return
|
||||||
if mute:
|
if mute:
|
||||||
pygame.mixer.music.set_volume(0.0)
|
pygame.mixer.music.set_volume(0.0)
|
||||||
else:
|
else:
|
||||||
pygame.mixer.music.set_volume(0.5)
|
pygame.mixer.music.set_volume(0.5)
|
||||||
|
|
||||||
def playLevel(self,lvl=1):
|
def playLevel(self,lvl=1):
|
||||||
|
if not sound:
|
||||||
|
return
|
||||||
if lvl == 1:
|
if lvl == 1:
|
||||||
pygame.mixer.music.load("""audio/level1.wav""")
|
pygame.mixer.music.load("""audio/level1.wav""")
|
||||||
elif lvl == 2:
|
elif lvl == 2:
|
||||||
|
@ -96,8 +100,12 @@ class Avocado:
|
||||||
pygame.mixer.music.play()
|
pygame.mixer.music.play()
|
||||||
|
|
||||||
def fade(self):
|
def fade(self):
|
||||||
|
if not sound:
|
||||||
|
return
|
||||||
pygame.mixer.music.fadeout(3000)
|
pygame.mixer.music.fadeout(3000)
|
||||||
|
|
||||||
def loadClick(self):
|
def loadClick(self):
|
||||||
|
if not sound:
|
||||||
|
return
|
||||||
self.click = pygame.mixer.Sound("audio/click.wav")
|
self.click = pygame.mixer.Sound("audio/click.wav")
|
||||||
return self.click
|
return self.click
|
||||||
|
|
12
game.py
12
game.py
|
@ -21,8 +21,14 @@ def initialize_screen():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.mixer.init()
|
try:
|
||||||
pygame.mixer.music.set_volume(0.5)
|
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!')
|
pygame.display.set_caption('Pin Avo, the Cado!')
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
@ -92,7 +98,7 @@ def main():
|
||||||
for i in range(avocados_in_game, level):
|
for i in range(avocados_in_game, level):
|
||||||
avocolor = colors[random.randint(0, 3)]
|
avocolor = colors[random.randint(0, 3)]
|
||||||
avosize = (50, 50) # should we randomize this?
|
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.append(a)
|
||||||
|
|
||||||
avocados[:] = [ x for x in avocados if x.exists() ]
|
avocados[:] = [ x for x in avocados if x.exists() ]
|
||||||
|
|
Loading…
Reference in New Issue