I am making a small game to test my skills.
I have an Entity class, which is the base class for pretty much anything. It has a Create function which renders my 2d sprite at a given x, y. That is what is similar to each entity, but each entity is different and I need to pass data to it that defines what kind of the specific entity it is.
Sounds confusing, so I'll try to show you what I mean:
Code:
struct EnemyDefinition
{
int image_number;
int health;
float speed;
char sprite_file[255]; //filename to use to make sprite
};
My create function would be:
Code:
Enemy::Create (int x, int y, EnemyDefinition *def)
Now that is just one Entity (Enemy is derived from Entity). Let's say I have a Player entity. The Create function would be the same, except it would be Enemy::Create (int x, int y, PlayerDefinition *def). The third parameter is different in each Entity so I don't think I can use a pure virtual function, yet what I am trying to do it seems like I should be using one - since every single Entity has a Create function. Is there a smarter way to do this?