How do people handle entities in their games?

Started by
2 comments, last by Flimflam 17 years, 9 months ago
I'm trying to work out the most elegant way of handling entities in my game, eg spaceships, bullets, missiles, smoke particles etc. Right now I've got a seperate class for each object type, which all inherit an Entity class. The world class stores a dynamic array of entity classes and updates them every loop, and has functions for adding and removing entites. The entities then can access the: World class, so it can add other entity objects, eg a missile can remove itself from the world when it's life reaches 0, and it's destructor calls for debris and fire to be created. Timer class, so it can calculate its own movement. Render class, so it can add itself to the render list It seems a bit hackish this way and I am yet to think of a way to implement collision detection into this structure, so i'm very interested in what other people have done in handling their objects/entities or if you have any suggestions at all. thanks
Advertisement
What I do is sort of a combination of approaches. I don't think it's ideal, but it works for now. I haven't spent much time trying to figure out how to refactor it either.

I have an entity class, which has some basic info in it, like name, etc. It also has a bunch of objects to represent its properties. For instance, it has three physics objects, one for the last simulation tick, one for the current tick ( for visual interpolation purposes ), and one for the visual tick.

It also has a separate collidable object to represent a sphere, capsule, box, etc for collision.

Each entity also has a visual object reference, which may be a particle system, a .x mesh, a cal3d mesh or a fluid.

Entities also have a 'type' which is just a general idea of which code path to follow in certain functions, like 'trap', 'weapon', etc. Entities in AG are everything from the player, enemies, urns, and weapons.

Entities may become inventory of another entity, so a weapon can be pick up. In this case, some of its processing is skipped and it is drawn with the holding entity.
All my entities are the same class. Anything unigue is handled by the scripting language. :)
I use generic classes for a lot of stuff, and just iterate through a list of them calling their common properties. They usually have an order of imporance tagged on, which gets the list sorted in the event something is added/removed. The order of impotance dictates what is executed first. so the elements with 0 will all get executed before say all the objects with an importance of 2.

This topic is closed to new replies.

Advertisement