Game design question - entity have all components VS entity reference other entity
Hi, I need some help with component-entity design
Let's imagine some people have 6 parts of body (head, body, two legs, two arms)
every body-part has its own health point (component) and can be damaged. then, what is good design?
-
people entity have all components! L-Arm, L-ArmHealthpoint, head, haedHealthpoint ...
-
people entity only has references to body parts, and body parts have same health component.
with the first design, checking "people entity has LeftArmHealthPoint component?" is really easy, but health point components are overlaps all body parts.
the second design is resuing same 'healthPointComponent' (nice!) but we can not check directly 'people entity have a LeftArmHealthPoint ?' This makes me using old OOP composition pattern. (people class have head class / and head class is an inheritance of body part class / ... blah blah)
anyone have guide about this?
(and when some monster have 4 arms, 6legs?)
personally i would go with something like this:
- IdComponent (every entity gets this, with an [PrimaryEntityIndex] attribute)
- HealthPointComponent
- BodyPartComponent: 1 Value which is an Enum of possible bodyparts (Leftarm1, Leftarm2, LeftFrontLeg, LeftMiddleLeg and so on)
- BodyComponent: List of Integers (IDs) (Or Dictionary<EnumBodyParts, Int> for simpler access)
a body part is an Entity with a BodyPartComponent, an IdComponent and a HealthPointComponent
the main entity then would have a BodyComponent with a list(or Dictionary) of IDs referencing the IDs of the body part entities. Hope that makes sense :D