Jump to content
  • Advertisement
Sign in to follow this  
Dalphin

How does a game work?

This topic is 1504 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 everyone,

For quiete a time i'm thinking of how games work.

When i see the directory of games (especially under contruction) i always see so many source codes.

for example a source code named Bullet, another named characters and things like that.

I always thought that you had so many different source codes for different things and then one (main) code,

where it all gets put together in one game.

Is this true and if not, could you explain me how it works then.

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

Most of the times using different files for different things is just for organization, it's easier to add new things or fix bugs if you have a file with code that is related and everything about it is there.

 

The "main" file doesn't "put togheter" everything, it's just some piece of code that uses other pieces and you can (and will) have other pieces of code that uses some other pieces apart from the main one. For example, you can have a file with physic simulation code that uses the code from other files too (like a RigidBody file).

 

Every program has an entry point, which is the first thing that will be executed when the program starts, and at that point the code would check for different conditions to do different things. In a game and other visual applications the "main" code will have a piece of code that runs forever in a loop until you quit or will start some other code that does that. It's kind of standard to name that code "main", but it's not really different from other source code.

 

Anyway, when talking about programming you have a lot of things happening that depends on more factors. In some languages like C you do end up with one compiled file that has all the code in it (you don't have to make it, there's a compiler that will do it) even if you wrote different files. In other languages like JavaScript you have all different files that you have to put in one file if you want to (for optimization maybe).

 

Programming is really complex and, like Buckeye said, there are books about it. There's no short and easy answer for your question, and more important, there's not a unique answer. You should try to learn how more simple applications work before looking at a game's source code.

Share this post


Link to post
Share on other sites
The reason you will see code split into various sections is primarily for organisation, though sometimes things like encapsulation will necessitate that you split up your script somewhat. A full game will often have hundreds of lines of code, and for someone looking through that (eg. Someone else on the dev team) it can be a pain in the rear to work through all that to find the code they need to work on. So, the code will be split up into separate scripts, each taking charge of a particular part of the game. The "Bullet" script you mention might take charge of drawing the bullet on screen, giving it a velocity, and dealing with impacts against enemies. Then another "damage" script might in turn reference the bullet script, saying that if the bullet hits an enemy, then an amount of damage, within a certain range, will be inflicted.

This method allows other coders to just go straight to the bit of code they want. As for encapsulation, it also minimises the chance of a fellow programmer accidentally affecting a bit of code that you want to be left alone.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!