Menu music now pauses instead of starting over in cases of stopping for game play. Added learn sounds.

This commit is contained in:
Storm Dragon 2019-12-01 18:57:17 -05:00
parent 77ad77831e
commit 696839880e
2 changed files with 46 additions and 7 deletions

View File

@ -119,14 +119,51 @@ def display_text(text):
event = pygame.event.clear() event = pygame.event.clear()
time.sleep(0.001) time.sleep(0.001)
def learn_sounds(sounds):
loop = True
pygame.mixer.music.pause()
i = 0
soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"]) and (f.split('.')[0].lower() not in ["game-intro", "music_menu"])]
# j keeps track of last spoken index so it isn't voiced on key up.
j = -1
while loop == True:
if i != j:
speak(soundFiles[i][:-4])
j = i
event = pygame.event.wait()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE: return "menu"
if event.key == pygame.K_DOWN and i < len(soundFiles) - 1:
i = i + 1
if event.key == pygame.K_UP and i > 0:
i = i - 1
if event.key == pygame.K_RETURN:
try:
soundName = soundFiles[i][:-4]
sounds[soundName].play()
continue
except:
j = -1
speak("Could not play sound.")
continue
event = pygame.event.clear()
time.sleep(0.001)
def game_menu(*options): def game_menu(*options):
loop = True loop = True
pygame.mixer.music.load("sounds/music_menu.ogg") if pygame.mixer.music.get_busy():
pygame.mixer.music.set_volume(0.75) pygame.mixer.music.unpause()
pygame.mixer.music.play(-1) else:
pygame.mixer.music.load("sounds/music_menu.ogg")
pygame.mixer.music.set_volume(0.75)
pygame.mixer.music.play(-1)
i = 0 i = 0
speak(options[i]) # j keeps track of last spoken index so it isn't voiced on key up.
j = -1
while loop == True: while loop == True:
if i != j:
speak(options[i])
j = i
event = pygame.event.wait() event = pygame.event.wait()
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE: exit_game() if event.key == pygame.K_ESCAPE: exit_game()
@ -138,12 +175,13 @@ def game_menu(*options):
if options[i] != "donate": pygame.mixer.music.unpause() if options[i] != "donate": pygame.mixer.music.unpause()
if event.key == pygame.K_RETURN: if event.key == pygame.K_RETURN:
try: try:
j = -1
eval(options[i] + "()") eval(options[i] + "()")
continue continue
except: except:
j = -1
return options[i] return options[i]
continue continue
speak(options[i])
event = pygame.event.clear() event = pygame.event.clear()
time.sleep(0.001) time.sleep(0.001)

View File

@ -59,9 +59,10 @@ def game(mode):
return "menu" return "menu"
# Game starts at main menu # Game starts at main menu
mode = game_menu("start game", "instructions", "donate", "credits", "exit_game") mode = game_menu("start game", "instructions", "donate", "credits", "learn sounds", "exit_game")
while mode != "exit_game": while mode != "exit_game":
if mode == "menu": mode = game_menu("start game", "instructions", "donate", "credits", "exit_game") if mode == "menu": mode = game_menu("start game", "instructions", "donate", "credits", "learn sounds", "exit_game")
if mode == "start game": mode = game(mode) if mode == "start game": mode = game(mode)
if mode == "learn sounds": mode = learn_sounds(sounds)
time.sleep(.001) time.sleep(.001)