Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where can I find good (well organized) examples of game code? I'm hoping that I can pick up some organizational tips. Most examples in books are too short and leave out lots of detail for the sake of brevity. I'm particularly interested on how to group your variables and methods so that another programmer would know where to look in the code. For example initializers at the top, then methods that take input, then methods that update views.

I don't care about a particular language, as long as its OOP. I looked at the Quake 2 and 3 sources, but they're straight C and not much help for getting tips on organizing your objects.

So, have you seen some good source? Any pointers to code that makes you say "wow, that's well organized" would be great.

share|improve this question

closed as too broad by congusbongus, Byte56 May 20 '15 at 5:50

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

This isn't really a direct answer, so I'll just leave it as a comment. I recommend checking out the book Large-Scale C++ Software Design by John Lakos. It was very enlightening for me. – BRaffle Aug 16 '10 at 14:14
up vote 17 down vote accepted

Several commercial games have had their source code released. Some of the games are listed here. There's no guarantee that the code in these is well organized, but by looking at some source code from games that were commercially successful you might get a good idea what works in practice.

Also, while not a game, OpenSceneGraph has many of the components of a game and is well architected in C++, using different design patterns, plug-ins, etc. It's a big enough code base and has been around long enough that you can learn a lot from it.

share|improve this answer
Thanks, the Wikipedia list was useful. Spring is really well organized - all the methods are grouped by general function (load/save, drawing, etc) Aquaria made me feel better about my own code organization:… I shouldn't criticize though, real artists ship. – smasher Jul 25 '10 at 15:55
I would add Ogre as a good reference with OpenSceneGraph... – Klaim Oct 14 '10 at 16:39

Battle for Wesnoth is a:

Free, turn-based tactical strategy game with a high fantasy theme, featuring both single-player, and online/hotseat multiplayer combat

Free as in open-sourced, under GPL. I just found/downloaded it, so can't say what the gameplay is like yet, but it's gotten great reviews. Nor do I know if their code is "well-organized" :) But hey, it's open-source.

share|improve this answer
Really funny :) :p – Qchmqs Apr 9 '12 at 17:59

I'm pretty meticulous about my code, so you might find my in-progress roguelike Amaranth useful to skim over.

share|improve this answer

If you're looking for good OOP - I quite liked the object model of the Doom3 SDK.
Ogre3D is a heavy OOP design but I emphasise heavy as i think it's quite bloated with lots of examples and plug ins.

Let me know what you think.

share|improve this answer

I have source code to libraries and full games on my site Another Early Morning you can also find some projects on my GitHub page. Not all of it is a shining example of quality, but then that tends to happen when you want to ship something.

share|improve this answer

Prototype, winner of one of the Shmup-Dev competitions:

And the source code:

Since I'm a code newbie I can't say much about the quality, but just skimming over it gave me some insights. Have fun.

share|improve this answer

I've got the source for a simple one we're using for a code war competition at Windward Wrocks. I think it's well organized and it is pretty simple. But certain parts were created quickly, not well. With that said, even in the largest game development teams, there are parts in those that are written quickly, not well.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.