Advertisement

Class Question...

Started by April 18, 2001 11:41 PM
1 comment, last by JSCFaith 23 years, 9 months ago
Hey, Well, as you might already know, I am creating a small breakout clone to learn Directx and to improve my use of classes. Well my question is that I have 3 classes: Ball, Paddle, Block. I need to check for collisions. After reading a book on classes it had said that it is not good practice to make the class relie on other parts of the program. So, I am wondering. Should I create funcion called Collision that all the classes relie on? Or should I create a Collision class? Or should I have each class do its own Collision test? Also, I want to add a menu interface to this program. Would you say I should create one class called "Menu" to do this or should I create multipule classes to do different functions? Well, as you can see, I am still not totally sure what the criteria for a class is. I hope to learn this over time, but for now I am still not sure. Well if you can help me out that would be appreciated. Thanks. Edited by - JSCFaith on April 18, 2001 12:45:41 AM
What you seem to need to do is to have a base class and then inherit from it.

ie.

class GameObject
{
GameObject (); // constructor
~GameObject (); // destructor

int CheckCollision (); // checks for collisions.

...
};


Etc. This class defines a BASE for ALL objects you need. Then símply inherit the class for each object

ie.

class GameBALL : public GameObject
{
BALLSpecificMethod ();
};

class GamePaddle : public GameObject
{
PADDLESpecificMethod ();
};
... And so on.

This way all objects will share the collision method, you may also add other functions that the different objects may share (functions that would look the same for all objects).

This is quite basic C++ coding, perhaps you should read some more about C++ programming in general .

Gluck,
Advertisement
Thanks a lot. I am suprised I never thought of that. I am just not used to this class stuff. Well thanks a lot.

Later.

This topic is closed to new replies.

Advertisement