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

Started by
4 comments, last by larspensjo 11 years, 2 months ago

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.

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.

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.

In the “Structure” section of this article there are plenty of tips (and reasons) for things to consider regarding the organization of your code.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.

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.

[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

This topic is closed to new replies.

Advertisement