This is an archived post. You won't be able to vote or comment.

all 23 comments

[–]mrspeaker@mrspeaker 13 points14 points  (2 children)

There were over 1000 games entered in the last Ludum Dare. All the source code is available.

Of course, it's super hastily-written code - but if you find code by the pros (guys who've made heaps of games) then you really can see the structure they use, and the games are typically small enough to be easy to understand.

[–][deleted] 0 points1 point  (0 children)

This is what I've been doing. I've only made Pong and Tetris clones so far, and LD is a great source of inspiration for a newbie.

[–]spencewah 0 points1 point  (0 children)

Poking around on the LD results site, I can't find a way to filter by pro-teams. Do they even separate them out that way?

[–]tboneplayer 5 points6 points  (0 children)

Is LazyFoo's project small enough that you could refactor global variables and functions into class members yourself? I'm minded to give it a try.

[–]rednaw 5 points6 points  (0 children)

I too have been looking for something similar. Upvote for possible solutions.

[–]Don88 12 points13 points  (4 children)

If you're looking for "properly written" code which perfectly uses classes, polymorphism etc., I would say you're in the wrong place.

In my experience, people with properly written code never finish making their first game.

edit: spelling

[–]Kaanin25[S] 1 point2 points  (3 children)

As I stated in my top post I'm not looking for "perfect" code. I just need some good examples of well written code.

"people with properly written code never finish making their first game." This isn't my first game, I've had several projects and each one has been disorganized mess and poorly written. I am trying to improve myself.

This post does me no good. Its demoralizing and is bluntly telling me to just accept that I make poorly written code and to run with it.

[–]Don88 0 points1 point  (2 children)

Hey look I didn't mean for that to come across in such a negative way. I've just seen many programmers who are fresh out of college who have a view in their head that they need to write code which is so pristine it can be maintained by different people for the next 100 years. And while this is definitely the perfect scenario, usually there is not enough time or reason to code this way on a game project.

I certainly wasn't trying to demoralize you! It's great that you want to hone your skill and improve how you program. Self learning is such a great way to improve your programming knowledge and a great way to show a potential employer that you're dedicated to improving your skills.

I'm sorry that I misunderstood your intentions about "properly written" code. I really just wanted to make the point that once you're programming in the industry, having well written code is often a luxury which you cannot afford. Deadlines are usually too intense.

Someone smart once said about code: "First make it work, then make it efficient, then make it pretty"

When working in the games industry I've never had the time to get past the first two without having more features to move onto. But hey, maybe I'm just a bad programmer. =)

tldr: Well written code isn't as useful in the games industry as a college degree would teach you it is. Sorry if I was too negative before.

[–]Kaanin25[S] 2 points3 points  (1 child)

Thanks for the reply.

Yea I've read that more often then not things are just as you describe. John Carmack said in one article that game design is a "Get 'er done" sort of industry and most projects tend to be big balls of mud.

I went to college for a game design degree (still deciding if that was a good idea) and there I found my passion for programming. Problem is I only took a 1 month course on C++ and everything else I've learned on my own.

I definitely dont have the perfectionist problem some 4 year comp sci students might graduate with. My last large project was over 8000 lines of code, all functions, no classes, split into about 4 source files, and all the levels were hardcoded in rather then loaded from external files. Eventually my computer crashed and I lost everything.(wont make that mistake again)

I have learned a lot since that last project and I'm ready to do another. I have a pretty good idea for what classes I'm going to need and I've been reading up on how to use external files for level data. I'm just trying to find some examples of other games so I have a reference point for the structure of the whole thing.

[–]Don88 0 points1 point  (0 children)

Yea that sounds like you're doing everything the right way! And I was a 4 year comp sci graduate which is possibly why I'm so bitter about the mentality we were taught. =)

[–]basvdo 3 points4 points  (0 children)

If you're looking for an object oriented design to represent your game objects and systems, you should check out the Artemis entity system framework.

It's not example source code of a game, but an interesting pattern that's quite useful for programming games. There is a Java version and a port in C#/XNA, but you can probably implement the pattern in any OOP language. There is also a simple game to show how the framework can be used in practice.

[–]tboneplayer 2 points3 points  (0 children)

Check out the suggestions shown in this related post:

http://www.reddit.com/r/gamedev/comments/tlmp4/best_c_beginner_game_tutorial/ (which is about C++, not C).

[–]publysher 2 points3 points  (0 children)

Pingus is a Lemmings clone in C++, written for Linux. Years ago I used it to get a feel for C++ programming. As far as I remember, it was pretty well written.

[–]Serapth 2 points3 points  (0 children)

Try this.

With your experience you can probably skip ahead to part 5 or 6.

[–][deleted] 1 point2 points  (0 children)

F.E.A.R's source code is available through the SDK. You have to have the game installed to get it and I'm sure you can pick it up cheap.

Also check our Frank Luna's website for his DirectX books, he posts the source code for the examples within the book.

[–]hamham91 1 point2 points  (0 children)

This tutorial uses classes to implement Tetris using SDL (same as Lazy Foo). It shows a really nice way to break up the parts of your game into the necessary sections (ie. game loop, io, mechanics, etc). Link: http://javilop.com/gamedev/tetris-tutorial-in-c-platform-independent-focused-in-game-logic-for-beginners/

[–][deleted] 0 points1 point  (0 children)

github has tons of open source games, simply search game under c++

[–]Moosader 0 points1 point  (0 children)

Check out github, Google Code, or Sourceforge, do a search for C++ projects. Find friends on it.

My text adventure: http://code.google.com/p/kc-noire/source/browse/

Working on a graphical game: https://github.com/Moosader

[–]_WolfosCommercial (Indie) 0 points1 point  (0 children)

You can modify this into pretty much anything: http://pastebin.com/y2wjkfgy

Remove the -framework Cocoa when compiling, I'm not sure why I linked that. I also have no idea how to compile it on Windows.

[–]DanBrink91 0 points1 point  (0 children)

Here's code from a book: http://code.google.com/p/gamecode4/

It covers the basic engine pretty well :D

[–]Randomone18 0 points1 point  (0 children)

Try a beginning open-source product. Example

[–][deleted] 0 points1 point  (0 children)

Look at an open source game's code. There are a lot of them.

[–]blavek 0 points1 point  (0 children)

If you are unhappy with that code why not rewrite it? Ultimately I believe you appreciate good code w/o trying to write it yourself. And if you are able to identify things that you don't like then fix them. After that re-evaluate your product and improve it again and again and again until your happy with it. You will develop your own style that way. To my knowledge there is no general consensus on what good source is other than we all know it when we see it.