@monfik using an entity-component-system (ECS) approach that I use in my engine, I should do this…
Monfik said:
I have Tower (Base class) andTower Based classes like Archer Tower, Fire Tower, Stone Tower etc.. Each Tower has own data like armor reduction, fire damage etc…
entity: tower1 (id1)
component: position (x,y,z,wx,wy,wz,… )
component: archer (range, damage points, …)
component: fire (range, damage points, …)
component: image (tiles, 3D mesh, ….)
entity: tower2 (id2)
component: position (x,y,z,wx,wy,wz,… )
component: fire (range, damage points, …)
component: image (tiles, 3D mesh, ….)
Monfik said:
if I have 7 Towers (FireTower, IceTower, Sand Tower etc…) and they have 3 levels of upgrade I will have 21 behaviours,
In order to upgrade a component (behavior data), I see two options:
- replace the component with a new one
upgrade("tower1", archerv1, archerv2) → inside this function, you copy the old data from archerv1 to archerv2 - Include upgrade options inside the component
archer (level, range[], damage[], points[], …) → and just change level=2, it cold be just the index of the parameters arrays → damage[level]
Pure ECS use only data in the component (struct, POJO). The behavior is in the Systems.
Systems know how to use the component data, they know the structure, and use those data to apply the behavior.
Some systems could be the following:
Archer system
For each component.archer and component.position do … damage enemies in range
Fire system
For each component.fire and component.position do … damage enemies in range
Draw system
For each component.image and component.position do … draw
So if you want a new tower type, just create a new system (behavior) and new data (component). And add the components to the tower (entities) that you want.