[SDL] Where SDL goes in your game

Ryan C. Gordon icculus at icculus.org
Wed Nov 8 12:06:33 PST 2006


> So it is better to keep everything minimal under the fewest number of 
> classes. I must admit, I do tend to want to "over" organize my programs 
> but I will think this over. Anyone else have any other suggestions?

It's C and not C++, but consider "PongThing" to be your class in this 
example:

     http://icculus.org/~icculus/tmp/sdlpong.c

This just used a color and coordinates for a rectangle, but you could 
swap those out with an SDL_Surface for each PongThing if you wanted to 
do real graphics.

In the case of Pong, you don't really care about specializing balls and 
paddles, the generic "thing" concept fits both fine, since they have the 
exact same properties...no real need for a subclass. That one PongThing 
is in an array named "paddles" and the other is in an array named 
"balls" is really all the distinguishing needed.

Peter's absolutely right: you don't want to go class-crazy. 
Over-designing something ruins it before you even get started on 
coding...knowing when to _stop_ planning and structuring is a zen art 
learned over many years...as is learning that global variables aren't 
necessarily evil, no matter what the textbook says.  :)

--ryan.





More information about the SDL mailing list