From ec7e9d3461df2ec483f40eb6166cab3249e45952 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 10 Dec 2019 14:12:15 -0500 Subject: [PATCH] Improved learn sounds. Added optional menu-move and menu-select sounds. --- libstormgames.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libstormgames.py b/libstormgames.py index 3483f20..752eca3 100755 --- a/libstormgames.py +++ b/libstormgames.py @@ -33,6 +33,18 @@ import time localConfig = configparser.ConfigParser() globalConfig = configparser.ConfigParser() +class scoreboard(): + 'Handles scores and top 10' + + def __init__(self): + self.oldScores = [] + for i in range(9): + try: + self.oldScores[i] = read_config("scoreboard", i) + except: + self.oldScores[i] = 0 + + def write_config(writeGlobal = False): if writeGlobal == False: with open(gamePath, 'w') as configfile: @@ -187,12 +199,15 @@ def learn_sounds(sounds): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return "menu" if event.key == pygame.K_DOWN and i < len(soundFiles) - 1: + pygame.mixer.stop() i = i + 1 if event.key == pygame.K_UP and i > 0: + pygame.mixer.stop() i = i - 1 if event.key == pygame.K_RETURN: try: soundName = soundFiles[i][:-4] + pygame.mixer.stop() sounds[soundName].play() continue except: @@ -202,7 +217,7 @@ def learn_sounds(sounds): event = pygame.event.clear() time.sleep(0.001) -def game_menu(*options): +def game_menu(sounds, *options): loop = True if pygame.mixer.music.get_busy(): pygame.mixer.music.unpause() @@ -222,13 +237,26 @@ def game_menu(*options): if event.key == pygame.K_ESCAPE: exit_game() if event.key == pygame.K_DOWN and i < len(options) - 1: i = i + 1 + try: + sounds['menu-move'].play() + except: + pass if options[i] != "donate": pygame.mixer.music.unpause() if event.key == pygame.K_UP and i > 0: i = i - 1 + try: + sounds['menu-move'].play() + except: + pass if options[i] != "donate": pygame.mixer.music.unpause() if event.key == pygame.K_RETURN: try: j = -1 + try: + sounds['menu-select'].play() + time.sleep(sounds['menu-select'].get_length()) + except: + pass eval(options[i] + "()") continue except: