I am working on my first Tower Defense game and I got stuck with architecture. I found some past Q&A this post"Should the entity handle his own movement?" and, read about Entity Component approach, and decided to stick with it.
What I want to achieve. I want to have different scripts that are responsible for different behaviors. For Example If unit contains IEnemy script than it will follow predifined path of the level. If it has IDamagable script it can receive damage, If it has Health script than the damage will affect health. So inexample:
if a unit contains an
IEnemyscript then it will follow predefined path through the level.If it has an
IDamageablescript it can receive damage.If it has a
Healthscript then the damage will affect health.
In order to create friendly unit all I have to do is throw away IEnemythe IEnemy script and add IFriendlyUnitthe IFriendlyUnit script.
In order to do that, I decided to have some storage and a manager of that storage. ManagerThe manager will have methods like heal(healthPoints)Heal(healthPoints), removeArmorPoints(armorPoints)RemoveArmorPoints(armorPoints),addArmorPoints(armorPoints) AddArmorPoints(armorPoints), DecreaseHealthBy(damage)DecreaseHealthBy(damage).
But the problem is that If I want to have Damagablea Damageable script which has only one method ReceiveDamage() thanReceiveDamage() then it needs to have a reference to the StateManagerStateManager in order to inflict damage and Itit breaks the design because Itit forces me to add the StateManagerStateManager script to the GameObjectGameObject in order to remove some healthpointshealth points and I cannot easily add independend Damagablean independent Damageable script to the object.
I want to decouple my code as much as possible and stick to SOLID principles, but seems like I am either over engineering or choosing the wrong way.
Will be very happy to read your recommendations. Thank you in advance.