My game is a dodge ball game and I am struggling with handling the state between the ball and the player. Right now both have a state machines that handle individual state. Here is what the ball state machine looks like for example:
What I am having difficulty with specifically syncing the player and AI with the ball so that both know who it is attached to. This was easy with just one player but now that I’m adding AI into the mix handling a many-to-many relationship is a lot harder.
What are some design patterns I could use to simplify this?
A many to many state machine could probably be simplified. There are methods for reducing state machine complexity.
Logically, your player has the ball or not. If teams matter, then it is “does team have ball or not”. If it’s a free for all, then it’s just do I have ball or not.
I see one or two extra bits of state. But you can also have more complicated systems running under a single state. Like more state machines, or a target system.
There are no rules to programming, and I don’t think there is another design pattern here to save you, other than learning how to breakdown the problem into simpler parts, and then deciding what patterns can be applied to reach your goal.