Component based design, but components rely on eatchother
- by MintyAnt
I've begun stabbing at a "Component Based" game system.
Basically, each entity holds a list of components to update (and render)
I inherit the "Component" class and break each game system into it.
Examples:
RenderComponent - Draws the entity
MovementComponent - Moves the entity, deals with velocity and speed checks
DamageComponent - Deals with how/if the entity gets damaged...
So. My system has this:
MovementComponent
InputComponent
Now maybe my design is off, but the InputComponent should say things like
if (w key is down)
add y speed to movement
if (x key is down)
Trigger primary attack
This means that the InputComponent sort of relies on these other components. I have to do something alone the lines of:
if (w key is down)
{
MovementComponent* entityMovement = mEntity->GetMovement();
if (entityMovement != NULL)
add y speed to movement
}
which seems kinda crappy every update.
Other options? Better design? Is this the best way?
Thanks!