Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 microlizard   Members   -  Reputation: 103

Like
0Likes
Like

Posted 17 February 2013 - 12:46 PM

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.



Sponsor:

#2 microlizard   Members   -  Reputation: 103

Like
0Likes
Like

Posted 17 February 2013 - 12:52 PM

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.



#3 HonestDuane   Members   -  Reputation: 151

Like
1Likes
Like

Posted 17 February 2013 - 03:58 PM

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.



#4 L. Spiro   Crossbones+   -  Reputation: 13279

Like
2Likes
Like

Posted 17 February 2013 - 04:12 PM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 microlizard   Members   -  Reputation: 103

Like
0Likes
Like

Posted 17 February 2013 - 09:39 PM

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.



#6 larspensjo   Members   -  Reputation: 1526

Like
0Likes
Like

Posted 18 February 2013 - 12:31 PM

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.


Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS