def main(): # Display menu for player pygame.font.init() screen = pygame.display.set_mode((640, 480), 0, 32) menu = KezMenu( ["New Game", lambda: optionX("new_game")], ["Load Game", lambda: optionX("load_game")], ["Quit!", lambda: optionX("quit")], ) menu.mouse_enabled = False while True: events = pygame.event.get() menu.update(events) screen.fill((150, 150, 150, 255)) menu.draw(screen) pygame.display.flip() if OPTION_SELECTED: break if OPTION_SELECTED == "quit": print("Aww, that's too bad! See you next time!") pygame.quit() sys.exit() else: # Initialize game object game = Game(S_WIDTH, S_HEIGHT, P_WIDTH, P_HEIGHT, TILESIZE, WHITE) # Load last saved game if it exists if OPTION_SELECTED == "load_game": if (game.save_exists()): game.load() # Start game game.run() # When exiting save game game.save(game.get_tiles()) # Close game pygame.quit() sys.exit()
def main(): # Display menu for player pygame.font.init() screen = pygame.display.set_mode( (640,480), 0, 32 ) menu = KezMenu( ["New Game", lambda: optionX("new_game")], ["Load Game", lambda: optionX("load_game")], ["Quit!", lambda: optionX("quit")], ) menu.mouse_enabled = False while True: events = pygame.event.get() menu.update(events) screen.fill( (150,150,150,255) ) menu.draw(screen) pygame.display.flip() if OPTION_SELECTED: break if OPTION_SELECTED == "quit": print("Aww, that's too bad! See you next time!") pygame.quit() sys.exit() else: # Initialize game object game = Game(S_WIDTH, S_HEIGHT, P_WIDTH, P_HEIGHT, TILESIZE, WHITE) # Load last saved game if it exists if OPTION_SELECTED == "load_game": if(game.save_exists()): game.load() # Start game game.run() # When exiting save game game.save(game.get_tiles()) # Close game pygame.quit() sys.exit()
OPTION_SELECTED = 1 def optionX(p): global OPTION_SELECTED OPTION_SELECTED = p menu = KezMenu( ["First option!", option1], ["sEcond", option2], ["Again!", option3], ["Lambda", lambda: optionX(71)], ["Quit", sys.exit], ) menu.mouse_enabled = False def drawMenu(): screen.fill((150, 150, 150, 255)) menu.draw(screen) pygame.display.flip() pygame.display.set_caption("Example 1: Use the KezMenu freely") while True: events = pygame.event.get() menu.update(events) screen.fill((150, 150, 150, 255)) menu.draw(screen) pygame.display.flip()
def option3(): global OPTION_SELECTED OPTION_SELECTED = 1 def optionX(p): global OPTION_SELECTED OPTION_SELECTED = p menu = KezMenu( ["First option!", option1], ["sEcond", option2], ["Again!", option3], ["Lambda", lambda: optionX(71)], ["Quit", sys.exit], ) menu.mouse_enabled = False def drawMenu(): screen.fill( (150,150,150,255) ) menu.draw(screen) pygame.display.flip() pygame.display.set_caption("Example 1: Use the KezMenu freely") while True: events = pygame.event.get() menu.update(events) screen.fill( (150,150,150,255) ) menu.draw(screen) pygame.display.flip() if OPTION_SELECTED: break