How would I make Mobs from this code? I know I can use vectors but how would that make every single Mob react to colision, death, etc? I know I can code functions to do that but how will the vector use my functions?
Ok. I don't know how your game is supposed to work but say that you are storing your Mobs in a vector. std::vector<Mob> mobs
If Mob has a function update() that updates the mod. It could be updating the position, velocity, making decisions and such things. To call the update() function on all mobs you can use a loop.
1 2 3 4
for (std::size_t i = 0; i < mobs.size(); ++i)
{
mobs[i].update();
}
If you want to do collision detection and call the MobIsHit() function when the Mob is colliding with another Mob, and you have a function isColliding that returns true if the two Mobs passed to it is colliding, you can use a nested loop to check every mob against each other.
1 2 3 4 5 6 7 8 9 10 11
for (std::size_t i = 0; i < mobs.size(); ++i)
{
for (std::size_t j = i + 1; j < mobs.size(); ++j)
{
if (isColliding(mobs[i], mobs[j]))
{
mobs[i].MobIsHit();
mobs[j].MobIsHit();
}
}
}
In that case you will have to store pointers in the vector std::vector<Mob*> mobs;. You can also use smart pointers if you know how they work. Which functions to be virtual is up to you.