Jump to content
  • Advertisement

Archived

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

SpazBoyTheMitey

Overall program structure

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

Okay, so I have made a handful of projects now and up until this point my biggest successes have been when I write in a non-OOP language like C. Now the problem I have when I am working in C++ is that I have problems with figuring out where to put certain types of data. For example, I am working on my dprvisl* little interpretation of the classic game asteroids. (* this word is actually "special", but some half naked women came on the TV and I lost control of my keyboard) Now I have a class for the ship, a class for the asteroids, and a class for bullets. The ship class contains a list of bullets, and each class contains its own data for display & collisions etc. Now, and this happens every time I try it in C++, when it comes to working out how the collision detection is going to work, I find that I have all this good collision data worked out, and I know what methods I want to use, but all the data is protected in all those different bloody objects. So, I guess what I am trying to say here is that I need to learn a little more about OOP design, and I''m wondering if anyone can help out with good links or an impromptu lesson. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You might be better off keeping the bullets in a global list rather than within the ship. If each bullet has to know it's owner (so you can mix alien ship and player ship bullets without them hitting each other), just keep an owner pointer with each bullet.

Depending on how you want to do the collisions, query each pair of objects for their collision information (say a circle):


Circle plcirc = player->GetCollisionCircle();

Circle astcirc = asteroid[ i ]->GetCollisionCircle();

if( Hits(plcirc,astcirc) )
player->DoDeath();


Similarly for bullets

if( bullet[ i ]->GetOwner() == player )
{
BulletCol bcol = bullet[ i ]->GetCollision();

foreach( asteroid j )
{
Circle astcirc = asteroid[ j ]->GetCollisionCircle();

if( Hits(bcol,astcirc) )
asteroid[ j ]->DoDestroyed();

}
}


That gives an extremely rough idea of one way to do it (I don't pretend or care if it is 'proper' OO technique, but it is clear and it works).

[edited by - JuNC on February 9, 2003 10:06:53 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!