To be specific I'm trying to implement this into a small game. What I'm thinking of is having a base/default class for derived objects such as player, enemies, tiles and so on and later the derived classes would inherit this base class and add whatever is needed depending on the object.
Right now the base class contains all the basic variables needed and all the basic virtual functions. I'm thinking of making that the base class would have a constructor and parameters to initialize all the default variables and the derived class would add anything if needed in its own constructor, though this would mean I would have to add all the basic parameters which I would use in the base class constructor for initialization to the derived class constructor by using such syntax: classB(int x) : classA(x)
and I think it's a bit too much work, I would like for a more automatic method.
Anyways, sorry for a long and hard to understand post, I would like some tips on how I should design such things. Posting some code below just clearance:
class Object
{
protected:
fRect box_obj;
float xVel, yVel, maxVel;
float speed;
std::string surfaceName;
World* world_ptr;
b2Body* body;
Surface* sur_obj;
Rotation* rot_pnt;
public:
virtual ~Object(); //Virtual methods defined in the .cpp file
virtual void move();
virtual void show();
void set_angle();
};
And the Player:
#include "Object.h"
class Player : public Object
{
public:
Player(fRect fr_obj, World* bWorld, Surface* sur, std::string surName, bool isDynamic = false, bool rotatable = false);
void handle_input(SDL_Event& event);
void move();
};
But like I've said, this is a current method of mine which I think might need some work. I'm initializing those parameters in the derived class.