• Advertisement
Sign in to follow this  

A question about how to organize in code, a small game project

This topic is 1795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been practicing with C/C++ as well as SDL 1.2. I can follow most tutorials, without too much problem. I'm ready to move onto a small 2D game project, but I am not sure how to organize the structure of the source code. The 2D game project would be a top down game like the original Zelda or Gauntlet. Does anyone here have experience with this? Any suggestions or example code could be helpful to me.

 

I'm working with Windows 7 64bit, mingw (32bit) with SDL. I am using Grafx2 and Gimp for simple test graphics. I'm not focusing on asset development whatsoever at this time, just code.

 

So to recap, I don't have an outline or structure for my source code because I just got to where I am and I have never done this before.

 

Any help would be great and small easy to read examples would be even better.

Share this post


Link to post
Share on other sites
Advertisement

I forgot to mention as a side note. I am looking into doing the 2D rendering with opengl. The lazyfoo.net opengl tutorials are excellent help, but limited to just explaining the graphics, obviously. Either way, I'm interested in both regular SDL and opengl 2D rendering techniques and how other components of the game would fit together.

Share this post


Link to post
Share on other sites

This may help you:  http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)

 

What you are asking for is overly general; So I'm giving you a very general answer and that is that in most code bases its good to keep in mind that as long as classes have one responsibility, they are closed for modification but open for extension by design, and you follow all the OOP rules, you should be good.  If you need to learn these rules first, then I suggest you invest in a book called "Clean Code".  Most of the code samples are in java but the things it teaches will make you a better programmer in any language for any project, even if you disagree with some of the things the author :(Commonly simply known as "uncle bob") says.

Share this post


Link to post
Share on other sites

I'm looking over the links now. Thank you.

 

L. Spiro, that's a great article. The Game/Engine structure is the next one I'll look at.

Share this post


Link to post
Share on other sites

There is one high level design pattern I really can recommend, and that is the Model-View-Controller. A short summary:

  • The Model can be seen as the physical model. It will manage objects in the game, and how they interact with each other, and attributes.
  • The View knows about the presentation to the player. This is where the OpenGL goes. The View understand the model, and knows how to present the various states.
  • The Controller takes care of all input (mouse, keyboard, timers, ...), and tells the Model and View to act accordingly.

There are more advanced version of the MVC pattern, but this is a good start. For every class and file you have, make sure you clearly document to what part it belongs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement