[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Standard methodology for different game screens
On Sat, Sep 19, 2009 at 7:13 PM, Pablo Moleri <pmoleri@xxxxxxxxx> wrote:
> Hello,
>
> I'm going through a game code written in pygame, the game shows different
> screens:
> - an introduction
> - a menu
> - and then it enters to different game modes.
>
> For each of these parts there's a different pygame loop, which doesn't seem
> right.
> I would like to know if there's a standard way to use pygame in this
> scenario.
>
> Thanks in advance,
> Pablo
>
>
Not really.
this is how I do it... I encapsulate my game.Game states in classes.
each has these methods:
- handle_events(events)
- update(elapsed_time)
- draw(screen)
- load()
Each of the game.Game classes can have children game.Games. Each of
the children ones get passed in events, elapsed_time and the screen.
This way I can have my intro run, and when it's done deactivate it,
and activate another part of the game.
class Top(game.Game):
def load(self):
self.games.append(Intro())
Anyway... that's the basic idea. There's lots of other ways of doing it.
cu,