One way to do this is to use nested loops. An outer loop calls functions which each contain their own inner loop. Each inner loop function will return either the inner loop function that should run next or None. If None is returned instead of a function, then the program exits.
Here's a template for you:
import pygame
def main():
"""one main loop to rule them all"""
pygame.init()
screen = pygame.display.set_mode((500, 500))
func = menu
while func is not None:
next_func = func(screen)
func = next_func
pygame.quit()
def menu(screen):
"""main loop for menu
mode"""
# Clear screen
# Put your menu's main loop here
# To run minigame_1, set chosen_game to minigame_1 and exit the loop
# To run minigame_2, set chosen_game to minigame_2 and exit the loop
# To quit the application, set chosen_game to None and exit the
loop
return chosen_game
def minigame_1(screen):
"""main loop for minigame_1"""
# Clear screen
# Put your first game's main loop here
return menu
def minigame_2(screen):
"""main loop for minigame_2"""
# Clear screen
# Put your second game's main loop here
return menu
if __name__ == "__main__":
main()
Jason
From: Astan <k12umm@xxxxxxxxx>
To: pygame-users@xxxxxxxx
Sent: Monday, November 4, 2013 8:50 PM
Subject: [pygame] Pygame minigames
Hi,
I'm trying to make a sort of game in pygame that is a collection of minigames (that may or may not be timed-based). The problem I'm having is developing something like this. I was wondering if it was possible to make the main interface of the game with pygame normally for menus, etc and then making these minigames with pygame as well and then combining them.
Currently, I'm having problems combining these two files/modules since they both init pygame and do various background manipulation.
Are there any examples of something like this that might help me?
Cheers
Thanks
--
"To make a photocopier, simply photocopy a mirror."