Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Any game is about event loops.</p> <p>So to structure your game:</p> <ol> <li>Have a module representing the game loader loop, which renders the GUI of those buttons. A good practice is to have most (or even all, really) GUI rendering outside and before the event loop, then have the event loop + bunch of if-else statements to listen to button clicks.</li> <li>Have each button click represents a specific event, and delegates what would happen after clicking each button to separate functions, which take on the duty of importing and loading the specific game modules (other .py's).</li> <li>You could alternate the behavior of the main window so the game loader GUI is gone and the specific game takes and reuses it, or simply spawn another window for the specific game.</li> <li>[Alt to 2] You can place your actual game logics in different threads within a single module which also hosts the game loader loop. Use this way properly could result in a more responsive overall game experience (e.g switching out of a game would go back to the other thread that runs the game loader loop while it's still hot in memory)</li> </ol> <p>A poor illustration of how this could be done:</p> <pre><code>import pygame import game_module_one # your game logic # two, three, four... # Your game loader def main(): # Initialise window pygame.init() window = pygame.display.set_mode((1024, 768)) # Bunch of rendering jobs, set fonts, draw buttons, etc. # Event loop while 1: for event in pygame.event.get(): if event.type == QUIT: return elif event.type == "start_game_one": do_game_one(window) #... # Game one loading function def do_game_one(window): # do something to that window if you intend to pygame.display.flip() game_one_module.start() </code></pre> <p>Consider the <a href="http://pygame.org/docs/ref/" rel="nofollow">reference</a> on mouse, event, display and surface</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload