Inheritance, monster base class

Hi there currently creating a small game with graphics using Allegro 5.
Though I am having some issues on which is the most proper way to create several monsters without having to create them all individually.
Here's what I have now.

Monsters.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef MONSTER_H_
#define MONSTER_H_

class Monster
{
private:
	int health_; //Current health

protected:
	Monster();

public:
	virtual ~Monster();
	virtual void attack();
};

#endif 


Monsters.cpp
1
2
3
4
5
6
7
8
9
10
#include "Monsters.h"

Monster::Monster()
{
}

Monster::~Monster()
{
}


Say I want a monster called Blob and a monster called Goat, where would I go from here if I would like to add monsters that inherit from this monster class, the proper way?
Last edited on
The proper way is to have each species be a subclass of Monster.
The proper proper way is use C++ only for resource management and various other low level functions, and write the game logic itself in a different language. So, instead of classes like 'Monster' and 'GelatinousCube', you'd have 'Sprite' and 'AudioDevice'.
Lua is a common option for this second language.
Hi, not really what I was looking for but I guess it could help in the future.
Keep in mind I am still new at programming and just looking for an answer for my question.
Which is a proper way to create a sub monster class, say a blob or a dragon, that inherits from the monster class.
I reckon all monsters have Hitpoints, Strength, Defense, Drops, Attacks etc.. I heard a good way of organizing this is using inheritance.
Can you give me an example? :)
Alright, for example,
1
2
3
4
5
6
7
8
9
10
11
class Blob : public Monster{
public:
    Blob(){
        this->health_ = 10;
        this->damage_min_ = 5;
        this->damage_max_ = 10;
    }
    void attack(Object &target) const{
        target->do_damage(random(this->damage_min_, this->damage_max_));
    }
};
oooo, thanks, this was helpful :)
Topic archived. No new replies allowed.