Dividing game between files
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!
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, but this post is probably a good start.
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, but this post is probably a good start.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement