-
Notifications
You must be signed in to change notification settings - Fork 0
Entities and MobHandler
This page describes the idea behind the Entity class and how they are handled.
Anything that exists in the world at a particular location. More specifically, at the time of writing there is planned to be two types of entities: Mobs and Particles.
Ultimately, the EntityHandler must be able to quickly find the closest Mob to the player.
Another requirement is that the EntityHandler must be able to run functions across all entities. Lastly, each entity should be updated according to its class update function (ie. mobUpdate()
).
To satisfy all these requirements I think it best that Mobs be in a separate array. However, to be consistent, all entities should have their own array. To iterate across all entities, each type of entity's array should be put into an array of vectors.
EntityHandler handler(world);
handler.update();
// ...
void EntityHandler::update()
{
for (auto &aray:entityArrays)
for (auto &entity:array)
entity.update();
}
BaseMob &EntityHandler::findClosestMob(int x, int y)
{
for (auto i : entityArrays[EntityType::MOB])
// ...