42
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – BRaffle
    Aug 16, 2010 at 14:14

7 Answers 7

19
\$\begingroup\$

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.

\$\endgroup\$
2
7
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Really funny :) :p \$\endgroup\$
    – Qchmqs
    Apr 9, 2012 at 17:59
5
\$\begingroup\$

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

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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

http://xout.blackened-interactive.com/ProtoType/Prototype.html

And the source code:

http://xout.blackened-interactive.com/dump/new/ProtoType_src.zip

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .