Component based design, but components rely on eatchother

Posted by MintyAnt on Game Development See other posts from Game Development or by MintyAnt
Published on 2012-11-26T04:36:32Z Indexed on 2012/11/26 5:24 UTC
Read the original article Hit count: 208

Filed under:
|
|

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!

© Game Development or respective owner

Related posts about c++

Related posts about architecture