Tuesday, October 9, 2018

architecture - "The Game Object" - and component-based design


I've been working on some hobby projects the last 3-4 years. Just simple 2d and 3d games. But lately I have started a bigger project. Soo in the last couple of months I've been trying to design a game object class which can be the base of all my game objects. So after much try & die testing I turned to Google which quickly pointed me to some GDC PDFs and PowerPoints. And now I'm trying to get the grasp of component-based game objects.



I understand that the engine creates a game object and then attaches different components which handles things like health, physics, networking and whatever you make them do. But what I don't understand is how component X knows if Y has changed the state of the object. Like how does the PhysicsComponent know if the player is alive, because the health is controlled by the HealthComponent..? And how does the HealthComponent play the "player-died-animation"?


I was under the impression that it was something like this(In the HealthComponent):


if(Health < 0) {
AnimationComponent.PlayAnimation("played-died-animation")
}

But then again, how does the HealthComponent know that the game object it is attached to have a AnimationComponent attached? The only solution I see here is




  1. Have a check to see if a AnimationComponent is attached or not (Either inside the component code or on the engine side)





  2. Have components require other components, but that seems to fight the whole component-design.




  3. Write like, HealthWithAnimationComponent, HealthNoAnimationComponent, and soo on, which again seems to fight the whole component-design idea.






No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...