I'm a beginner both in game developping and programming.
I'm trying to learn some principle in the building of a game engine.
I want to create a simple game, I'm at the point where I'm trying to implement the game engine.
So I thought my game engine should control this things:
- Moving the objects in the scene
- Checking the collisions
- Adjusting movements based on collisions
- Passing the polygons to the rendering engine
I designed my objects like this:
class GlObject{
private:
idEnum ObjId;
//other identifiers
public:
void move_obj(); //the movements are the same for all the objects (nextpos = pos + vel)
void rotate_obj(); //rotations are the same for every objects too
virtual Polygon generate_mesh() = 0; // the polygons are different
}
and I have 4 different objects in my game: plane, obstacle, player, bullet and I designed them like this:
class Player : public GlObject{
private:
std::string name;
public:
Player();
Bullet fire() const; //this method is unique to the class player
void generate_mesh();
}
Now in the game engine I want to have a general object list where I can check for example for collision, move objects, and so on, but I want also that the game engine will take the user commands to control the player...
Is this a good Idea?
class GameEngine{
private:
std::vector<GlObject*> objects; //an array containg all the object present
Player* hPlayer; //hPlayer is to be read as human player, and is a pointer to hold the reference to an object inside the array
public:
GameEngine();
//other stuff
}
the GameEngine constructor will be like this:
GameEngine::GameEngine(){
hPlayer = new Player;
objects.push_back(hPlayer);
}
The fact that I'm using a pointer is because I need to call the fire()
that is unique to the Player object.
So my question is: is it a good idea? Is my use of inheritance wrong here?