• 13
• 15
• 27
• 9
• 9

# Actor Management in games?

This topic is 3239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a problem with managing game actors. Each actor is stored in a list of all game actors. The base class for all actors looks like this:
public class Actor
{

public ActorType Type
{
get;
private set;
}

public ActorID Id
{
get;
private set;
}

//. . . more unnecessary code
}


Each Actor has an identification number so that I can keep track of it. Each actor has a type. I was however, unsure of how to implement this. Should I put all actor types into a big enumeration?
public enum ActorType
{
Bullet,
AlienSpaceship,
HumanSpaceship,
Asteroid,
//etc...
}


This is what I have been thinking would be good but it just seems annoying to have to change the enumeration each time I add a new actor to the game. Is there a better way to do this? Please help.

##### Share on other sites
Actually I think you need to break things up a bit.

What are the different things your actors need to do.

IE. Collisions with the environment, collisions with other actors, AI actor, user actor, etc.

Then create class for those based on the base class. Then you can enumerate those specific types. This keeps the actions needed for any broad type in that type and not in the base class.

Just the way I would do it.

theTroll

##### Share on other sites
Generally I would stay away from using an enum unless its a very small game, like space invader or something, where there is practically no difference between the types behavior and internal data.

When you say you are going to use a base class for all actors I'm thinking that this is going to be something bigger where you need inheritance to factorize behavior and data into different classes.

Using both a class hierarchy and a type enum, like TheTroll suggests, bothers me a bit since they both kindof solves the same thing, which is to provide different behavior to different types.

Then again, at the end of the day I sometimes find myself using both anyway since using an enum only is too simple to do the job without a lot of switching, and using polymorphism and virtual functions only is too complex and requires more thought to get right.