Hello there.
I want to make a list of entities that are gonna be updated every tick. So, I created a class named Entity, and gave it a couple of functions:
class Entity{
public:
int uniqueID;
Vec3f loc;
Vec2f res;
Vec2f vel;
float rot;
virtual void onUpdate();
virtual void onSpawned();
virtual string getNameID();
vector<GameData> gameData;
};
Then, I created a vector of these entities:
vector<Entity> entities;
After that, I wanted an arrow entity, so I created a new class EntityArrow that is an extension of Entity:
class EntityArrow : public Entity{
public:
EntityArrow();
EntityArrow(Vec3f argLoc,Vec2f argRes);
string getNameID();
void onUpdate();
void onSpawned();
};
And now comes the problem, when I try to add a new EnttiyArrow to the entities list: entities.push_back(EntityArrow()); it is still treated as an Entity. For instance, if I overrided the onUpdate() function in EntityArrow to print out something in the console, it would do something that is in the Entity's onUpdate() , and not the EntityArrow's. I have already tried to make a vector out of references to Entity class : vector<Entity*> entities , but I still have a lot of problems with it.
Is there a better way to do it? Thanks in advance :).