Skip to content

Entities and MobHandler

Matthew D. Scholefield edited this page Jun 9, 2016 · 1 revision

This page describes the idea behind the Entity class and how they are handled.

What is an entity?

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.

EntityHandler functions

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.

Example code

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])
        // ...
Clone this wiki locally