Skip to main content
GameDev.net gamedev.net
🔒 Locked

Open source code for a beginner

Started by Kaanin25 Jun 6, 2012 at 1:58 AM 10 replies 7.2k views
Original Post
Kaanin25
Kaanin25
I have a firm understanding of C++ beyond the beginner stuff; I know classes, polymorphism, templates, ect... What I am looking for is some example source code that is properly written to look at. Something small and simple like Tetris or Snake, not huge like the Doom 3 source code.

I found this on LazyFoo's website. http://lazyfoo.net/g...locks/index.php and it's working code, but there are a lot of global variables, C style functions that should be part of a class object, and so forth. I'm not bashing his code, Ive written far worse myself.

I don't need perfect, I just need something with a good format as a reference. Something I can use whenever I hit a roadblock to look and see "how they did it".

Anyone know of or have any open source game code I can look at?
Cornstalks
Cornstalks

C style functions that should be part of a class object

I'm not so sure about that one. Not everything needs to be in a class, and it's ok to have free standing functions (and in many situations, it's the better thing to do). I'm not saying I'd recommend using that code as a guideline, and maybe you already understand this, but I wanted to point it out just in case because it's really easy to take OOP further than it should be (because not everything in code is an object).

Anyway, it's hard to give you meaningful code without knowing what it is you're looking for. I don't know if you're looking for design patterns, or algorithms, or syntax styles, or program flow, etc. Or maybe you're looking for all of them, in which case I think that's a massive question and needs to be broken down into bite sized chunks.

You'll find that in programming, you usually have to come up with your own solution (and it may suck). A lot of times, you won't understand "how they did it" until you understand the problem well enough to solve it on your own (even if your solution is crappy). At which point, you are more likely to meaningfully grok "how they did it." And usually, you don't understand "how they did it" by perusing through source code, but instead by presenting your solution/problem/roadblock to others and receiving their feedback. That is to say, you usually don't learn most of the important things from other people's source code, but instead by their normal english (or whatever language) words describing the high-level details. Once you understand the high-level details and the actual meaning/algorithm/design, you can trivially translate it into code. The code is just a low-level implementation of a high-level idea. Sorry, I'm going on a tangent now.
marvel_magnum
marvel_magnum

...
You'll find that in programming, ...


Very nicely put.
EnigmaticProgrammer
EnigmaticProgrammer
I found this open source project a long time ago through these forums. Although, the developer has not been quite as active lately and the code is a bit of a mess, it has given me some insight into how to design my engine. Personally, It was easier for me to understand than the source code for id Tech 3.
Lazy Foo
Lazy Foo

I found this on LazyFoo's website. http://lazyfoo.net/g...locks/index.php and it's working code, but there are a lot of global variables, C style functions that should be part of a class object, and so forth. I'm not bashing his code, Ive written far worse myself.


Notice how I very specifically noted that that the source for the game is how not to to make game, in bold and capslock so you know I'm serious.

You want to know the best way to learn design? Stop going around to other people's projects hoping you'll find some magical piece of wisdom and go out and get your hands dirty.
Learn to make games with my SDL 2 Tutorials
marvel_magnum
marvel_magnum
The Secret Mantra

You want to know the best way to learn design? ... go out and get your hands dirty.


Super awesome LazyFoo! Love ya!
DejaimeNeto
DejaimeNeto
Try checking Allegro SpeedHack, it's an allegro "contest" where people make simple games in a short time stamp (not like in hours, but still not years). The games' sources are available (or were). Worth checking!

Link speedhack.allegro.cc
Serapth
Serapth

You want to know the best way to learn design? Stop going around to other people's projects hoping you'll find some magical piece of wisdom and go out and get your hands dirty.



I agree and disagree with this. The best way to learn just about anything is by doing it, jumping in and getting your hands dirty.

That said, you can learn an absolute ton about design from other people. Past mentors, reading other peoples code, books. There have been some books that had a profound effect on my code, Effective C++, Code Complete, JavaScript:The Good Parts, Refactoring, Design Patterns to name but a few.

You jump right in to learn how to make shitty code; you read books, blog posts and talk to other developers to learn how to make it better.
Kaanin25
Kaanin25

Notice how I very specifically noted that that the source for the game is how not to to make game, in bold and capslock so you know I'm serious. smile.png


Notice how I very specifically noted that I was not bashing your code...I understand it was a tutorial designed with the intent to show beginners how to handle the SDL library and setup a very simple game; and for that purpose you did a fantastic job, your tutorial has been very sucessfull and I myself thank you for making it.


You want to know the best way to learn design? Stop going around to other people's projects hoping you'll find some magical piece of wisdom and go out and get your hands dirty.


So you just assume that im sitting around all day just parusing through other people's code without writing any of my own? That I havn't already gotten "my hands dirty". I have been writing code on and off for some time now; I have a few past projects under my belt. I am not an infinite pool of resources unto myself and when I lack the skill and knowlege to solve a problem I seek out others who are better then me for answers.

In my particular case I had a problem with the game I am developing right now and all the solutions I had come up with on my own have been unsatisfactory. I thought maybe I could get a look at few other open source projects made by better programmers to see how they did it.

learning by example is a very valid form of education. If you don't want to help that is fine, then dont post, but please don't berate me as if im not trying.
Sorry if that was a bit of a rant, but it really upset me. I came looking for help.

Thank you very much for the resources Serapth, EnigmaticProgrammer, and Dejaime.
sednihp
sednihp
I've put up some of my games over on my blog if you want some small SDL games to look at. They're nothing amazing (Pong, breakout, space invaders, bomber run clones) but they might give you something to peruse...

I will say, I've only been at this for 4-5 months so I'm no expert, but I'm pretty happy with my code.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.