It seems as if it would be simpler to just create one class and overload the constructor to accept the arguments each object needs while setting the rest to null values. Is this normally the way stuff like this is done? Or is it more common to set up inheritance hierarchies? |
Firstly I should admit that I have virtually no experience with game programming - I am just going on what I think might be logical.
Having one superclass for everything doesn't sound like a good idea IMO. An inheritance tree would need to be designed properly.
I can relate something that might give a bit of insight possibly. The situation is how to model Players, Enemies and Weapons.
With Weapons there lots of different types, but you can group them together based on properties they have in common - for example swords, daggers, knives etc; then there might spears, clubs, Crossbows, Bows. The model for this Would have a base class CWeapon , with the others in an inheritance tree going down from there. A common feature for all of them might be damage that can be inflicted on a player.
With Players & Enemies, they both move, can attack, receive damage, and possess & use weapons. So they might both have a base class called CActor.
As I said earlier, class design isn't necessarily easy - you have to think about how they are all going to interoperate. If you get the class design wrong then that will cause kinds of grief.
It is only worth using inheritance if it is going to help you.
The other thing is the concept of virtual functions. This allows the definition of a function high up in the inheritance tree, that is inherited to all the derived classes, but it may also be changed to reflect specialisation of a derived class. An example might be different Enemies that attack in slightly different ways. Or weapons that do different things.
The whole thing gets complex quickly - I am sorry I don't really have enough knowledge to help you, except I might be able
to see if something doesn't make sense. But there are plenty of guys & girls who ought to
know how to go about it in the first place.
Any way - really good luck !!!!!!