When implementing a new gameplay element, what is the most sensible method of keeping things flexible? Should I be looking at using components, interfaces or a combination of both?
At the moment, I’m using components only on the visual side of things, and interfaces for actual gameplay mechanics (such as health, inventory, shields etc). As an example, if I wanted to implement a shield mechanic, where damage taken by the actor is intercepted by the shield, which could then handle the damage dynamically, which approach should I take? My current approach is:
When an actor hits another an actor (I realise most of this is unnecessary, because actors have a TakeDamage / ApplyDamage system. this is just as an example)
- check if the actor implements the IDamagable interface (to see if the actor has the health mechanic implemented).
- Apply damage
- In the hit actor’s take damage function: check if the shield object exists (shield object is an actor that implements the ISheild interface). If it is, pass the damage straight to the shield object, which will handle it, and send the damage back to the actor if the shield is empty / not activated.
Alternatively, I could use components, and have a HealthComponent and ShieldComponent attached to the actor, and I could simply check if the actor has either of these components, rather than checking if they implement an inferface.