Thanks Thiago, it's a nice aproach, it helps to reduce coupling between the different screens/states. I'll keep it in mind :)
On Mon, Sep 21, 2009 at 5:27 PM, Thiago Petruccelli < thiagopetrucce...@gmail.com> wrote: > (there's a : missing by the way: > if self.state == 1: > > now it's right =D ) > -- > Thiago Henrique Petruccelli > > > > On Mon, Sep 21, 2009 at 5:26 PM, Thiago Petruccelli < > thiagopetrucce...@gmail.com> wrote: > >> Hi Pablo! >> >> I've been with that problem some time ago. I used a finite state >> machine... the main class, game, executes a loop like this: >> >> self.state = 1 >> menu = Menu(self.screen, self.clock) >> gameplay = Gameplay(self.screen, self.clock) >> while self.state != 3: >> if self.state == 1 >> self.state = menu.show_menu() >> elif self.state == 2: >> self.state = gameplay.mainloop() >> >> sys.exit(0) >> >> the var self.state indicates the actual state of the game(kinda obvious... >> :P). The while repeats until the state is 3, wich quits the game. the call >> to menu.show_menu() and gameplay.mainloop() returns an integer 1,2 or 3, >> wich changes to the next stage. Every class do it's own event handling, >> updating, drawing etc. >> >> Well, until now it worked fine to me. Good luck Pablo! >> -- >> Thiago Henrique Petruccelli >> >> >> >> On Sat, Sep 19, 2009 at 6:17 PM, Pablo Moleri <pmol...@gmail.com> wrote: >> >>> Thanks Devon, Claudio and René, I'll keep in mind your advices to try to >>> make the game structure cleaner. >>> >>> Regards, >>> Pablo >>> >>> >>> On Sat, Sep 19, 2009 at 5:30 PM, Devon Scott-Tunkin < >>> djvonfun...@yahoo.com> wrote: >>> >>>> A state machine or stack is a usual way to do it, where each state/scene >>>> has its own update stuff and event handling and the pygame loop just uses >>>> the current scene. >>>> >>>> --- On Sat, 9/19/09, Pablo Moleri <pmol...@gmail.com> wrote: >>>> >>>> > From: Pablo Moleri <pmol...@gmail.com> >>>> > Subject: [pygame] Standard methodology for different game screens >>>> > To: pygame-users@seul.org >>>> > Date: Saturday, September 19, 2009, 1:13 PM >>>> > 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 >>>> > >>>> > >>>> > >>>> >>>> >>>> >>>> >>> >> >