Merge branch 'master' into devel

This commit is contained in:
Jeremiah Ticket 2019-12-11 04:38:32 -09:00
commit 27d24006a2

View File

@ -34,19 +34,32 @@ 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:
with open(gamePath + "config.ini", 'w') as configfile:
localConfig.write(configfile)
else:
with open(globalPath, 'w') as configfile:
with open(globalPath + "config.ini", 'w') as configfile:
globalConfig.write(configfile)
def read_config(section, value, readGlobal = False):
if readGlobal == False:
with open(gamePath, 'r') as configfile:
with open(gamePath + "config.ini", 'r') as configfile:
return localConfig.read(section, value)
else:
with open(globalPath + "config.ini", 'r') as configfile:
return globalConfig.read(section, value)
def speak(text, interupt = True):
@ -69,8 +82,7 @@ def initialize_gui(gameTitle):
global globalPath
global gamePath
globalPath = BaseDirectory.xdg_config_home + "/storm-games"
gamePath = globalPath + "/" + str.lower(str.replace(gameTitle, " ", "-") + "config")
globalPath = globalPath + "/config"
gamePath = globalPath + "/" + str.lower(str.replace(gameTitle, " ", "-"))
if not os.path.exists(gamePath): os.makedirs(gamePath)
# Seed the random generator to the clock
random.seed()
@ -189,12 +201,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:
@ -204,7 +219,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()
@ -224,13 +239,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: