Hello there,
I've got a little problem with vectors containing class objects.
I want to create two
std::vectors containing:
1. objects of class:
class Mobs_normal
{
public:
int id;
string name;
int lvl;
int dmg_min;
int dmg_max;
int hp;
int critChance;
};
Which would be a kind of mob templates.
2. objects of class:
class Entity
{
public:
vector<Mobs_normal> mobsNormal;
void load()
{
// data base
fstream file_mobs_normal;
file_mobs_normal.open("entity/mobs_normal.txt", ios::in );
if (!file_mobs_normal.good() ) {error("mobs_normal.txt"); } // 404
// mobs were an int array, but i want them to be vectors
for (int i=0; i < 11; i++ )
{
mobsNormal.name.push_back() // ?
file_mobs_normal >> mobsStack[i].name;
file_mobs_normal >> mobsStack[i].lvl;
file_mobs_normal >> mobsStack[i].dmg_min;
file_mobs_normal >> mobsStack[i].dmg_max;
file_mobs_normal >> mobsStack[i].hp;
file_mobs_normal >> mobsStack[i].critChance;
}
}
void drawMobs(sf::RenderWindow & okno, Textures & cTex)
{
// temp drawing
for (int i=0; i < cTex.sprEntity.size(); i++)
{
cTex.sprEntity[ i ].setPosition((1+i)*50, 50);
okno.draw(cTex.sprEntity[ i ] );
}
}
void enableAiMovement(sf::RenderWindow & okno, Textures & cTex)
{
// moving objects on map and switches for "do something" methods
}
};
Which would be templates handling ai of objects drawn at the time on your screen, containing their movement and other actions on map.
I wonder if it's the best solution for this problem.
How should I create a vector containing all information of objects on map (to interact with Player)?
One for all those stats (id, name, lvl, hp) or one for every single stat? I would connect them with "id" iterator.
I want to achieve a quick access to those stats and sprite drawing methods by their
int id;Attachment: database with stats