7
\$\begingroup\$

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Kaj
    Jul 31, 2010 at 4:47
  • \$\begingroup\$ 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 \$\endgroup\$ Jul 31, 2010 at 4:52
  • \$\begingroup\$ 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. \$\endgroup\$
    – user744
    Jul 31, 2010 at 19:55
  • \$\begingroup\$ Very simply, I think what I need is an example of drawing graphics and taking input. \$\endgroup\$ Jul 31, 2010 at 23:05

7 Answers 7

3
\$\begingroup\$

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: http://www.spintz.com/electron/electron.html

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

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.)

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think the Quake 3 engine goes a bit over a few hundred lines ;o) \$\endgroup\$
    – Kaj
    Aug 1, 2010 at 17:07
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ I frequently recommend this book to beginners. I mean "I've never programmed before" beginners, so this may be TOO simple. \$\endgroup\$
    – jhocking
    Jun 10, 2011 at 21:11
0
\$\begingroup\$

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.

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

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.

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

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.

\$\endgroup\$
1
  • \$\begingroup\$ Since Paolo only ever mentions the one engine, other popular ones are: OpenSludge, Unity3D, AGS, AGE, Visionaire or Wintermute \$\endgroup\$
    – uliwitness
    Oct 21, 2016 at 14:36

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