I’m working on a flying game right now that uses a very simple state machine to track the player’s state and handle input. I have four states defined for ordinary flight at different speeds (Let’s call them normal, subsonic, sonic, and supersonic), each with their own camera behavior and handling characteristics, and each defined using subclasses and polymorphism. So far so good. Now I want to add in the ability to get short speed boosts when the player flies through a bonus ring or uses a boost item or something.
My first instinct was to just add another state for the boost that ramps up the speed over a few seconds and then returns to the proper flying state when finished. However, I want to have boosts from different sources behave differently: maybe one has a longer duration, or a different acceleration curve, or something. And they should stack with one another.
What would be a good way to implement this? I started with just adding more and more states, like BoostFlyingState, RingBoostFlyingState, BoostAndRingBoostFlyingState, etc etc, but this pattern seems like a bad idea for lots and lots of reasons.