I'm developing a top-down shooter in C++ using an entity-component system, and have run into a problem when attempting to refactor powerups. Currently I have a
PowerupSystem that is essentially a load of
if...else statements that directly modifies player entity attributes (for example speed).
I'd like to move towards using different powerup classes that inherit from a base
PowerupComponent class that encapsulate powerup behaviour. An example of this would be
SpeedPowerup. These derived classes would have a constructor that changes a value in the player entity, and a destructor that sets it back to its original value.
The problem I'm having is that the powerup constructors and destructors need access to the player entity data to make these changes (stored in my
World class), giving me a circular dependency issue.
The dependency is:
world -> powerup system -> powerup -> world
Any ideas on how I could overcome this issue are appreciated.
Thanks in advance, Rich.