Sign in to follow this  

Dividing game between files

This topic is 2322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! Ok, I'm getting the hang of state machines after a few people here directed me to some articles. Now I've found that my code is getting too long and I want to know how people usually divide their game into files. I know that different programmers may each have their own way of doing this but perhaps their is a way for a beginner to do this. Thanks!

Share this post


Link to post
Share on other sites
You are going to have to be Wayyyyyyy more specific.



Do you mean how do you seperate your source code into different files? Or do you mean how do you seperate game data into different files?

If you mean source code, what language are you using?



Being that this site is this site, I will assume you mean source code and that your language is C++. If so, well to be honest it's time to learn a bit more about programming. You either work in an object orriented manner and restructure your data as objects, and each object resides in its own cpp/h(pp) set of files which you link #include as needed. If you are working in a procedural style, you need to start moving functions into different c/h files and #including them in too.


The specifics of how are probably beyond this forum to teach and picking up a good book is probably your best idea.If you look for more advice from this forum on how to restructure your code, you are going to have to actually post the source code so it can be better illustrated.


It's an oldy, [url="http://www.gamedev.net/page/resources/_/reference/programming/languages/c-and-c/organizing-code-files-in-c-and-c-r1798"]but this post[/url] is probably a good start.

Share this post


Link to post
Share on other sites
What language are you using?

Usually this is achieved by moving the code into a set of types and functions, and then organising these types and functions into files containing related functionality.

E.g, a simple game like Pong might be separated into an Input file, a Graphics File, a Paddle file and a Ball file. The Main file might contain the game loop that pulls this all together. There might be an additional file for helper functions which don't belong to any other file in particular, like collision detection routines, etc.

Share this post


Link to post
Share on other sites

This topic is 2322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this