Suppose I have a class Entity.
And then I have n number of classes which is derived from Entity
eg :
class Snake : public Entity{...};
class Mouse : public Entity{...};
Now I have a class player that is an entity.
Can I create a class player that inherits from any type of entity?
eg :
class Player : public Entity -->(but instead of entity be any type of entity)
Can this be done?
Is this achieved by using templates?
I've read that the templates can be explicitly specified in a cpp file i.e
template class Entity<Snake>;
I am trying to achieve the following
In my player class I have a moveCamera function inside move Now only when a player moves, the camera moves .. If an AI Snake moves the camera should not move.
this is my render function in the entity class which is virtual
void Entity::Render(float interpolation)
{
if(currentAnimation != 0){
float x = this->currLocation.x - (this->currentVelocity.x * (1.0f - interpolation)) - camera->getLocation(L_FACTOR_CURRENT).x;
float y = this->currLocation.y - (this->currentVelocity.y * (1.0f - interpolation)) - camera->getLocation(L_FACTOR_CURRENT).y;
currentAnimation->Render(x,y);
}
}
This is my gameUpdate function and basically moves an entity to its respective world co-ordinates
void Entity::GameUpdate(float gameUpdateDelta)
{
this->Move();
}
Therefore for my player's move function I will call the camera's move function and then call the base class's move function... Now is it possible to call the extended class of the base's class move function..
My Move function is virtual and therefore a snake and mouse can move differently..