Archived

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

Mkk

Need help with structuring game code

Recommended Posts

I´m working with breakout clone, just finished level editor last night.. There´s ~2500 lines of code now and I´m thinking of starting to do some structuring for it (separating code to many files, right now it´s almost all in one file). Problem right now is that I´m not really familiar how things work.. It seems like that when I add .cpp file in to my project (MSVC++ 6.0) it gets somehow automatically included? So I would like to know what´s really happening there..

Share this post


Link to post
Share on other sites
Basically you want this:


// function prototypes

bool startGame();
bool playGame();
bool quitGame();

// function definitions


bool startGame()
{
// this is where you intilize everything

if (somethingGoesWrong == YES) return false;
ctheClass myClass = new ctheClass;
int myArray[] = new int [];
return true;
}

bool playGame()
{
// this is where you run your loop

while (userDoesntDoThis)
{
if (somethingGoesWrong == YES) return false;
// do this

// do that

}
return true;
}

bool quitGame()
{
// this is where you delete everything you allocated

if (somethingGoesWrong == YES) return false;
delete myClass;
delete [] myArray;
// etc.

return true;
}

// main


void main(void)
{
if (startGame())
{
if (playGame());
quitGame();
}
return;
}



As far as being "automatically included" I''m not sure what you mean. Did you create an empty workspace (solution/project in .NET)? If not, the IDE handles the #includes for you






"Do not flame people you don''t know in a public forum. Only amateurs do that. Professionals in the industry know they will run into each other over and over. The person you flame this year may the person you want to do business with next year. Don''t burn your bridges," (Diana Gruber, http://www.makegames.com/chapt6.html).

Share this post


Link to post
Share on other sites
I guess you mean that the .cpp file is listed automatically in the available project files.

Yes, that''s true, MSVC++ 6 does this automatically. This affects mostly the make-file, because the .cpp-files in your projects will be automatically compiled and linked for you (I remember the times where you had to do that all on your own *fg*).

As far as the "structure" is concerned: I prefer splitting up my projects into logical sections. Whenever I use classes, each class definition will go in a .h-file and each implementation of the methods will go in the corresponding .cpp-file (e.g. if I have the class c_myclass, the definition of it will be in the c_myclass.h and the implementation of the functions in the c_myclass.cpp file).

If you do not have classes, I would split it up into pieces "that might be a class" (kinda bad language, dunno how to write it correctly ).
By this I mean putting all the graphical stuff in a graphics.cpp, collision detection in colldect.cpp and so on.

Whatever system you prefer, STICK TO IT! ... this will make finding specific parts ways easier ... especially when the project becomes really huge ...

Hope that helped!


Indeterminatus

--si tacuisses, philosophus mansisses--

Share this post


Link to post
Share on other sites
EDIT: Edited my post off so no one won´t try to answer it, after experimenting and reading graveyard filla´s topic I started to understand the stuff.

Thanks.

[edited by - Mkk on March 20, 2004 9:59:13 AM]

Share this post


Link to post
Share on other sites
mkk....

i have recently gone through the same thing as you. my pacman clone started getting huge and it was all in one file, but i had no clue where to start. anyway, you should read the thread i posted a week or so ago. it got a lot of replies that cleared everything up for me.

CLICK HERE TO READ THREAD

[edited by - graveyard filla on March 19, 2004 12:26:28 PM]

Share this post


Link to post
Share on other sites