[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Enter name before game starts



On 2010.4.27 3:01 AM, Alex Nordlund wrote:
Basically, I'd like to have the game start, present a screen for the user
to enter their name, then move to the main game loop.


I solved this by having a state variable in my game's mainclass, one
that keeps track of where the game is.
Thanks to sjbrown I have a very nice way of handling input so it was
easy as pie!

I do state management with a homemade module called "ringtale" ( http://kschnee.xepher.net/code/ringtale.py.txt ). The idea is that there's a main loop that handles Pygame events (including QUIT), and calls self.Logic() and self.Draw(), where those two functions are redefined based on a current state. Eg. if it's told to push a state called "Spam" onto its stack of states, it'll look for functions named SpamDraw and SpamLogic, and say self.Logic = self.SpamLogic until further notice. So that's one way of doing things like a name-entry screen, even in the beginning or middle of another set of functions.