Help with basic game pattern

Hi, I’m new. :slight_smile: I’m trying to write a game using Panda 3d, so I hope I’ve found the right place.

So, there’s a basic pattern in game writing that I’m trying to implement with Panda, and I’m sort of stumped. The pattern is fairly simple (and easy to do in PyGame, which I’d be using if I wasn’t writing a 3d RPG):

  1. Game starts with a splash screen, fades to GUI. The GUI is basically “New Game”, “Internet Game”, “Settings”, that sort of stuff. Whatever you choose, eventually you’ll enter the game.

  2. Game. You’re looking at your character and moving around, shooting bad guys, deciphering Ancient text (yes, it’s a Stargate ripoff).

  3. Ingame UI: This is where you can leave the server, quit the game, whatever. Change video options on the fly if you’re in framerate hell, whatever.

The standard pattern I know to do this is basically a state machine, which Panda supports nicely. If the state is (1), make the main GUI object active. If the state is (2), make the game object active. If the state is (3), make the Ingame UI object active and show updates to the Game object behind it.

Ok, so all of that said, how do I do that sort of switching? I don’t want to destroy objects, necessarily, to do it. But I’ve found exactly 0 examples of this sort of thing. Lots of great examples that I’m eventually going to copy, paste, and modify, but nothing like this.

Um, help? :wink:

Welcome! :slight_smile:

There might be more elegant ways of approaching this, perhaps involving Panda’s state-machine class, but one simple approach might be to keep references to each item (the main menu, the current level, etc.), and to show and hide them as called for (this might be encapsulated in a base class, and accessed via “activate” and “deactivate” methods). In the case of objects that are updated each frame (such as the current level), keep a variable that points to the current object to be updated, calling that object’s “update” method each frame, and change which object that variable points to as appropriate.