From 870b8b39c0c780141b75bb6479325d910e6c1b2b Mon Sep 17 00:00:00 2001 From: Storm dragon Date: Wed, 23 Mar 2016 13:40:30 -0400 Subject: [PATCH] More progress on menus. --- mine-racer/mine-racer.py | 3 ++- mine-racer/storm_games.py | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/mine-racer/mine-racer.py b/mine-racer/mine-racer.py index 9cce713..26de60c 100755 --- a/mine-racer/mine-racer.py +++ b/mine-racer/mine-racer.py @@ -8,7 +8,8 @@ mode = "menu" gameName = "Mine Racer" sounds = initialize_gui(gameName) -# loop forever (until a break occurs) +# Game starts at main menu +mode = game_menu("start game", "credits", "exit") while True: # wait for an event event = pygame.event.wait() diff --git a/mine-racer/storm_games.py b/mine-racer/storm_games.py index 645a11c..1c64f8d 100755 --- a/mine-racer/storm_games.py +++ b/mine-racer/storm_games.py @@ -5,6 +5,7 @@ import os from os import listdir from os.path import isfile, join +from inspect import isfunction import pygame import speechd import time @@ -43,12 +44,36 @@ def game_menu(*options): speak(options[i]) while loop == True: event = pygame.event.wait() - if event.key == pygame.K_ESCAPE: exit_game() - if event.key == pygame.K_DOWN and i < len(options) - 1: - i = i + 1 - speak(options[i]) - if event.key == pygame.K_UP and i > 0: - i = i - 1 + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: exit_game() + if event.key == pygame.K_DOWN and i < len(options) - 1: i = i + 1 + if event.key == pygame.K_UP and i > 0: i = i - 1 + if event.key == pygame.K_RETURN: + if isfunction(options[i]): + speak(options[i] + "() is a function.") + options[i]() + else: + speak(options[i] + "() is not a function.") + return options[i] speak(options[i]) event = pygame.event.clear() time.sleep(0.001) + +def credits(): + info = { + gameName + "brought to you by Storm Dragon",\ + "Billy Wolfe, designer and coder.",\ + "http://stormdragon.tk",\ + "Press escape or enter to return to the game menu."} + i = 0 + speak(info[i]) + while loop == True: + event = pygame.event.wait() + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN: return + if event.key == pygame.K_DOWN and i < len(info) - 1: i = i + 1 + if event.key == pygame.K_UP and i > 0: i = i - 1 + speak(info[i]) + event = pygame.event.clear() + time.sleep(0.001) +