Archived

This topic is now archived and is closed to further replies.

saetrum

Suggestions for game organization

Recommended Posts

I''ve decided to dive into my first 3d game. I''ve followed tutorials to create both a Tetris and Breakout Clone, but now I wanted to start on something a little more difficult. However, I am having a hard time deciding on how to organize my game. I am going to use C++, and make use of the Direct X common files where I can. The game idea is: 2 players choose spaceships, and then try to blow each other up (something like Star Control 3 melee), and then the winner gets to purchase upgrades for his ship and fight another opponent. I know it isn''t wildly creative or orignal but its where I wanted to start. I currently have the idea for an Object Class, which has a mesh file name, a matrix for position, size, rotation, etc. Then a Ship class which is a subclass of Object, a Weapon class which is a subclass of Object (for weapons that need to have a mesh, missiles for example). I have a switch statement in my frame move function which has each of the "states" the game can be in (combat_begin, combat, combat_end, intro, menu, game_end, shopping, etc.) I am just wondering how I should organize this idea into class better. I don''t want to have to write a ton of code in one function, I like have it modular. So how would you experienced folks set this up? A combat engine class, a menu class, etc...? Thanks for the help.

Share this post


Link to post
Share on other sites
That''s the way I do it. One class for each "state" that the game could be in. Each is derived from a common abstract class, which provides some virtual methods that each state implements. The game app just keeps a pointer to the current state.

Take care,
Bill

Share this post


Link to post
Share on other sites
So for example, the main app would have a pointer to a Game_State class (the abstract base class), and would have subclasses of the type: Menu, Combat, Ship Selection, etc. Each of those subclasses would implement functions like: frame_move, render, etc?

Have I understood correctly?

Share this post


Link to post
Share on other sites
Pretty much. This is the State pattern as documented in the ''Design Patterns'' book. Just define the common operations that take place in all states (doesn''t matter if one or two of them don''t do anything meaningful - just define an empty function), and your loop can then call the virtual functions through a pointer and it''ll do the ''right thing''. All you have to worry about then is changing from old state objects to new ones.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites