Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Donuts

Over the top OO?

This topic is 5508 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

So, I''m making this crappy little platformer and I am trying to make everything nice and object oriented. However I think I may have either gone over the top or even strayed entirely from having an OO design. I have placed EVERYTHING in classes. I have put the basic drawing functions into a CGraphics class, all Input is in a CInput class and the CGameEngine class contains the two previous classes. I was then going to make a GameObject class a derive all of my little guys and crap like that from it. But am I actually gaining anything by doing this or am I just making my program a hell of a lot more complex? -Donuts

Share this post


Link to post
Share on other sites
Advertisement
Actually I think it''s a good idea to do it like you did it...

the good think about a design like that is that if you ever want to use another API for the graphics you just have to replace the CGraphics class...

if you''re going to support other input devices just replace CInput... (ok in that case replacing is not a good idea... a polymorph class would be a better idea and you just derive new classes from it).

so you can have a lot of advantages making a string OO approach. But the question is if it makes sense for what you''re doing now. If you''re doing a PacMan clone I wouldn''t suggest using such a complex design, but for more complex games it can be really helpful to have a nice OO design.


I hope this helps a bit... ;-)



--
Programmer of Star Torn


--

There are only 10 types of people in the world:
Those who understand binary, and those who don''t.

Share this post


Link to post
Share on other sites
The first time you realize that you have gained something will be when you have your GameObject and those who are derived from it. GO_Player, GO_Box, GO_Ballon, GO_BouncyBall all have a Update method which they implement diffently (the Player checks for input, the box just sits there, the ballon goes up until he hits the ceiling and the BouncyBall ... bounces) and which was still pure (or default implemented) in the GameObject.

Once you have an array of GO_ objects all stored in a GameObject** vector you can walk the length of the vector, updating each entry. And each one will react as befits a Object of its type. No bouncing boxes or players that float to the ceiling.

Sure OO seems like huge overhead but once the code of your app grows beyond two screens you''ll be happy for maintainabilty

---------------------------
I may be getting older, but I refuse to grow up

Share this post


Link to post
Share on other sites
I don''t see how this is wrong, its organized isn''t it?

Only thing wrong is sticking C on your classes.

Share this post


Link to post
Share on other sites
quote:
Original post by Donuts
But am I actually gaining anything by doing this or am I just making my program a hell of a lot more complex?

You''re not giving enough details for anyone to give a proper answer to that question.

"Putting everything in classes" doesn''t in itself make your game OO.



AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.

Share this post


Link to post
Share on other sites
oh, this is something that makes me crazy, too. i realised that i spend most of my time scribbling engine-desings and walking up and down all the night, thinking about what would be the best structure for everything. "do i need an extra "Room"-class? or should i implement the funtionality in the "core"-class? where belong the NPCs to?" etc.
often im ending up rewriting parts of my code, because what looked good yesterday just looks crap today. and maybe good again tomorrow. i just can''t find a nice, clean implementation...
and theres also very few material about general engine-design available...

Share this post


Link to post
Share on other sites
quote:
Original post by Donuts
I have placed EVERYTHING in classes.

I have put the basic drawing functions into a CGraphics class, all Input is in a CInput class and the CGameEngine class contains the two previous classes. I was then going to make a GameObject class a derive all of my little guys and crap like that from it. But am I actually gaining anything by doing this or am I just making my program a hell of a lot more complex?


GOOD! I LOVE YOU! When you finally complete all your classes, you''ll find that it will make more sense. Even though creating it will sometimes get confusing, the end product will be idiot-proof.



Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda

Share this post


Link to post
Share on other sites
quote:
Original post by maximAL
often im ending up rewriting parts of my code, because what looked good yesterday just looks crap today. and maybe good again tomorrow. i just can''t find a nice, clean implementation...
and theres also very few material about general engine-design available...

That was me a couple of months ago. I have 8-10 older versions of my project.

I just strive to be as minimal as possible in the engine itself; in my current version the components do not even know of the engine. Obviously this isn''t always possible.

Share this post


Link to post
Share on other sites
IMHO, probably the most important thing in OO is to ask right questions. Something I have trouble with.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!