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

Are there any very simple open source games available just to demonstrate the basics of the programming techniques? Preferably something which fits in to a couple hundred lines of actual code. Specifically, I'm looking for an open source game written in Objective-C and Cocoa.

I would also appreciate one written in C.

All the projects that I find online are relatively complicated.

share|improve this question

closed as too broad by Sean Middleditch, Josh Petrie Dec 14 '14 at 23:54

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.

I guess part of the problem is that there hardly is such a beast as a 'simple game'. A game generally needs input handling, drawing code, game logic, resource loading, perhaps audio. That alone makes for a couple hundreds of lines of code. Add a menu and a hud and it grows. Even simple DirectX samples rather quickly grow to a few hundred lines, without counting the service functions in the sample framework, and there's just something being drawn to the screen without any game logic. – Kaj Jul 31 '10 at 4:47
I presume it is definitely much easier in Java, but still, snake was about 300 lines. Of course much of the underlying stuff isn't seen in a Java applet – mechko Jul 31 '10 at 4:52
Can you clarify what you mean by "the programming techniques"? The programming techniques for a 300 line game aren't the same as the techniques for a 30,000 line game, and those aren't the same as for a 300,000 line game. – user744 Jul 31 '10 at 19:55
Very simply, I think what I need is an example of drawing graphics and taking input. – mechko Jul 31 '10 at 23:05

If you want 200 lines, then the only type of game I can think of would be a good old-fashioned text adventure. :) Don't underestimate the challenges of that.

Here's a text adventure in Objective-C:

share|improve this answer

You can find a few open source games written in objective-c on github. Although most are larger than a few hundred lines.

If you're looking for "tiny" examples and you like Roguelikes, you should check out the listings for the 1kb roguelikes contest. There are a couple C examples that are rather clever (though they probably aren't good learning examples, just fun to read.)

share|improve this answer

If your interested in FPS you can look at Cube Engine.

Also the Quake 3 Engine is available for free. You can find it on the id Software website. Bottom of the right side bar.

share|improve this answer
I think the Quake 3 engine goes a bit over a few hundred lines ;o) – Kaj Aug 1 '10 at 17:07

I am, very slowly, teaching myself programming (only need to grasp basic game logic) with the free book "Invent Your Own Computer Games with Python".

It's written with the idea that all an aspiring game programmer wants to do is get to the point of writing games, so that is what it lets you do, from the very beginning. In the end you will be making games that are pretty much what you describe here.

share|improve this answer
I frequently recommend this book to beginners. I mean "I've never programmed before" beginners, so this may be TOO simple. – jhocking Jun 10 '11 at 21:11

An Allegro Game in 20 lines of code.

  • It can be considered "free to use" since it is snippets on public forum
  • C language
  • some "dirty techniques" how to squeeze code in C
  • some techniques how to make game simply
  • at most 20 lines (there are few exceptions and there is a problem that C is maybe too compressible, because there is almost no restriction on newlines or whitespaces; LOC is usually a bad metric)
  • Not sure if the "basics of the programming techniques" falls here, but there are certainly
    1. arrays
    2. function composition
    3. C boolean properties
    4. C comma properties
    5. C macro-processor properties
    6. C ternary operator
    7. boolean logic with multiplication and addition
    8. ...
  • You would need some math background to understand some of them.
  • Snippets have < and > instead of [ and ] .

There is also Pac-Man for example.

It is something I would reccomend You if You are more advanced programmer, because some of these techniques are quite non-readable.Nevertheless, it is a nice set of techniques. Proper way would not be to make such "abominations" but to properly design, document, test (...) Your program and such code would be the result of many compression techniques applied on very good design. Please, this is not how You should program but a demonstration how much a game can be compressed.

share|improve this answer

I've got the source for a simple one we're using for a code war competition at Windward Wrocks. It's in C# but that's close to Objective C.

share|improve this answer

Maybe it is a good idea not only look at open source games but to some freely available game systems (editors etc.) where you can find some inspiration for your data structures and what is behind it all. I mean for example GameStylus adventure game editor and engine, where - in the editor - you can clearly see what data structures are in the back of the game and how they are used.

share|improve this answer

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