   Trying to program a game, and I'd like a good example.
  Does anyone know a website that has source code for a simple game,but one that is done WELL ?   (preferrably in C++)I've looked around a bit and found a few games like Tetris.Unfortunately, everything I found had some really bad practices (goto, and other scary things...)Does anyone know of any good examples of how to do it right (good coding practices, readability, efficiency)?I saw a couple ways to do the main game loop, collision, and rendering, but I'm not sure they're were approaching things in the best way.I have Game Coding Complete, but that's a bit advanced for what I want to do now...   
  Try making tic-tac-toe. make a game state, reset state, start state, and some more state if you can think of it. Each state has its own meaning. And in you main make a switch statement for states.ex, switch(WhichState){ case startState : startFunc(); break; case gameState  : gameFunc() ; break;  case endState   : endFunc();   break;//and so on}This is good practice. I think the pros use similar approach for games. You don't have to make a tic-tac-toe. Just use the approach for any game.   ;  But why not use a more object-oriented approach and have:a GameState classsubclass it for PausedState, etc.and just do something like:stateStack.push( pausedState )and later:stateStack.pop().doDerivedStateStuff()This is why I'm asking...I'm not really sure what the best approach is when it comes to most of this stuff :(I can handle programming simple games, but I'd like to be more confident that I'm going about things correctly.;Quote:Original post by meteorstorm42I can handle programming simple games, but I'd like to be more confident that I'm going about things correctly.Experience will tell you if you are doing it right. Worrying about doing things right seems a fairly good starting point for me.About examples, you could search for GPL'd games like battle for wesnoth, supertux, and so on, but you don't have a guarantee they have good coding pratices. But you always can ask the developers why they did it in some way and not another.   ;  I think C++ is pretty hardcore to start programming a game in. There are much easier ways. What about something like Blitz Basic? You only should use C++ if you want to do state of the art 3D games where you need every bit of speed. If you are doing something like a simple 2D game or naughts and crosses (tic-tac-toe) then you should use something simpler.   ;Quote:Original post by meteorstorm42But why not use a more object-oriented approach and have:a GameState classsubclass it for PausedState, etc.and just do something like:stateStack.push( pausedState )and later:stateStack.pop().doDerivedStateStuff()A common trap to fall into for beginners being introduced to OOP is to start over-engineering everything.  Objects can help you improve code modularity and decrease complexity, but in the case of a Tic-Tac-Toe program, a design like this would only be increasing complexity, without providing any real benefits.Use objects to model your data, and try to shy away from "controller classes" like GameState - they're often more trouble than they're worth.  The only way to get a good sense of how to design programs is to just start designing them; you can always post your code here if you want comments on it.   ;Alrighty, guess I'll start doing the trial-and-error thing.I think I'll go with something I can handle first like Tetris or Breakout and then try something like a Jetpack game later.Afterwards, how do I tell if I designed it well? Guess I can look at loose coupling, modularity, etc?I know I don't really have to worry about efficiency in a 2D game with today's hardware, but I may as well build good habits.(By the way, I wanted to use C++ because I'd like to get a better grasp of it. Most of the classes I'm taking are taught in Java and C. I'd like to branch out a bit language-wise. Also, they don't stress efficiency enough in my classes...)I'd still like some examples if possible...   ;Quote:Original post by Captain_ThunderA common trap to fall into for beginners being introduced to OOP is to start over-engineering everything.  Objects can help you improve code modularity and decrease complexity, but in the case of a Tic-Tac-Toe program, a design like this would only be increasing complexity, without providing any real benefits.Yup. It's a real danger. On the other hand, it can be a healthy and educative experience... writing too much boiler-plate code for too little gain. As long as you realize it, of course. :)Quote:Use objects to model your data, and try to shy away from "controller classes" like GameState - they're often more trouble than they're worth.  The only way to get a good sense of how to design programs is to just start designing them; you can always post your code here if you want comments on it.Personally I find it useful to organize game-specific code in a game state class - as opposed to menu-related logic. It's just one part of organizing the code: a big, bloated, do-everything game state class is obviously a bad thing. But having a class to encapsulate the game parts of a program isn't a bad thing, imho. But yeah, it depends on the game.To the OP: don't worry about the best way. You're more than likely not doing things the best way. That's not really a problem, because the very best way is often not known. As long as you're doing something efficient enough, then it's ok.As for examples, I'm afraid I can't really give you some, but I can recommend a few books: 'The Pragmatic Programmer' for good programming practices in general, and 'Effective C++' for C++-specific tips. I'm currently reading 'Code Complete' - a big pill, looks pretty extensive so far.   ;  Yeah, I'm actually reading Code Complete now too (and the length is pretty daunting). I picked up Effective C++ but have only glanced at random items out of order so far.Hopefully those books will help. I definitely have a tendency to over-engineer... I'll have to be careful about that. I was considering getting the book Design Patterns.Would you suggest reading that soon, or waiting until after a few games?(I have a feeling it may add to my urge to over-engineer.)[Edited by - meteorstorm42 on May 24, 2009 6:11:23 PM];  I am at the same "state" as the OP.  I can make my game "no problem" by just programming it.However, I want to overengineer/OOD it to get practice with OOD.  I just read the first 6 chapters in Code Complete, too.  I also own Effective C++ and Pragmatic Programmer, but I haven't started on them, yet.  We all were probably recommended the same books to read.  :PI believe a good OOD will be useful for me especially, because I plan to prototype my game in OpenGL and port it to DirectX as I learn DirectX.   