Game Structure and Best Practices

Hi All,

I need some best practices advice on how to structure my game. Right now Im checking out the Epoch example and the author states in the programming notes:

I would like to know what people think about the way this game is structured and if you think this is a good or bad approach for structuring a game. Also, are there any MVC based approaches that exist?

Thanks,
Kory

well I dug inside that code and found was not that bad as stated in the advice - the problem is that there is a huge amount of code to study with and I would start with something smaller. Anyhow, my piece of advice is to think like “divide et impera” and avoid at any cost the use of global variables and functions but definitely use classes as much as you can.
Then is just a matter on put your fingers on the keyboard and make your own code and learn from the experience. To me that’s all about.

MVC is somewhat aided already - panda is the view. To do the other parts I would think of a World class to manage all of the objects in the scene, switching between scenes, and handling various “global” input (menus); and then classes for each type of game object (the model). For general coding guidelines, the best I can say is to keep each piece of the program manageable. If you have to scroll around to find out what something is doing, it makes it a lot slower to work with. When you make a class, don’t just make one big class with 50 methods dumped in there, try and get that class to work with other classes as much as you can. In panda or in any program.

I don’t have much panda experience, but the worst programs I have written have several thousand line modules, mostly due to huge classes that do too much.

I agree here. I too don’t have much panda experience, but have a fair amount of practice with C++. I have learned that for anything more complex than pong(and even possibly with pong), you want to work with classes as much as possible. Any objects should work separately from any other objects, and some objects can control interactions between other objects. Even with pong, you would have a class for the ball, which only controls the balls movement, and depending on the game engine, possibly the rendering. Then you would have another class for the paddle objects. Though you have two different paddles, you would probably use only one class for it, which recieves input, such as move up, and move down. You would probably have a class, which checks for collision between paddles and the ball, telling the ball to reverse direction if it hits a paddle, or giving points if the ball is outside an edge, while resetting the ball to an initial position. You would likely have a separate class to control player input, which would link up to a paddle, making it move. Another class would be AI, linking up to a paddle the same way the player input class would, so that there is no true advantage for the AI compared to the player, since they use the same type of paddle.

I’m pretty sure any complex game these days is done in this style, only on a much greater scale depending on the complexity of the game. My asteroids game I did with C++ and the Irrlicht engine had classes for everything, including the bullets, the ship, and the asteroids. I had another class that contained internally all of the above, which during its update function, would check for collision between the items. I also created the ship class in the same way as I described the pong paddle above, so that if I wanted to control the ship with an AI class, it would be the same ship being used, with its same internal commands, TurnLeft, TurnRight, Shoot, etc… This also creates an advantage should I want to have some kind of battle mode, two player mode, or even a demo mode, like something to show if the player is on the menu for a certain amount of time.

Truthfully, using classes in this way makes programming easier, by dividing problems into objects, so you can do one thing at a time, as long as it is planned for. I knew how my ship class was going to receive input, but my ship doesn’t care how the TurnLeft() is determined, whether by AI or a player hitting Left Arrow key.