Improved learn sounds. Added optional menu-move and menu-select sounds.

This commit is contained in:
Storm Dragon 2019-12-10 14:12:15 -05:00
parent 2b27ce97b7
commit ec7e9d3461

View File

@ -33,6 +33,18 @@ import time
localConfig = configparser.ConfigParser() localConfig = configparser.ConfigParser()
globalConfig = 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): def write_config(writeGlobal = False):
if writeGlobal == False: if writeGlobal == False:
with open(gamePath, 'w') as configfile: with open(gamePath, 'w') as configfile:
@ -187,12 +199,15 @@ def learn_sounds(sounds):
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE: return "menu" if event.key == pygame.K_ESCAPE: return "menu"
if event.key == pygame.K_DOWN and i < len(soundFiles) - 1: if event.key == pygame.K_DOWN and i < len(soundFiles) - 1:
pygame.mixer.stop()
i = i + 1 i = i + 1
if event.key == pygame.K_UP and i > 0: if event.key == pygame.K_UP and i > 0:
pygame.mixer.stop()
i = i - 1 i = i - 1
if event.key == pygame.K_RETURN: if event.key == pygame.K_RETURN:
try: try:
soundName = soundFiles[i][:-4] soundName = soundFiles[i][:-4]
pygame.mixer.stop()
sounds[soundName].play() sounds[soundName].play()
continue continue
except: except:
@ -202,7 +217,7 @@ def learn_sounds(sounds):
event = pygame.event.clear() event = pygame.event.clear()
time.sleep(0.001) time.sleep(0.001)
def game_menu(*options): def game_menu(sounds, *options):
loop = True loop = True
if pygame.mixer.music.get_busy(): if pygame.mixer.music.get_busy():
pygame.mixer.music.unpause() 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_ESCAPE: exit_game()
if event.key == pygame.K_DOWN and i < len(options) - 1: if event.key == pygame.K_DOWN and i < len(options) - 1:
i = i + 1 i = i + 1
try:
sounds['menu-move'].play()
except:
pass
if options[i] != "donate": pygame.mixer.music.unpause() if options[i] != "donate": pygame.mixer.music.unpause()
if event.key == pygame.K_UP and i > 0: if event.key == pygame.K_UP and i > 0:
i = i - 1 i = i - 1
try:
sounds['menu-move'].play()
except:
pass
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 j = -1
try:
sounds['menu-select'].play()
time.sleep(sounds['menu-select'].get_length())
except:
pass
eval(options[i] + "()") eval(options[i] + "()")
continue continue
except: except: