i was wondering what are the best practices for restarting the game, say for example in a platformer game when you die the game restarts and you have to reposition all the characters or reset the traps or what have you.
I thought two ways for doing this:
1) You have some level or scene manager that has a reference to all the things that should react to a game state change ,for example when restarting level, you would tell every character to reposition itself or something like that.
2) You have events. Every character or entity will subscribe to this level manager to an event like "OnLevelRestart" using delegates or function pointers, then when the manager restarts the level, it would trigger the event and all the ones who have subscribed to that event, will be informed and reset their own state.
The first approach seems more flexible because i have a reference to those objects, and i can send other kind of messages to them. so if in the future i want to do something different with those objects i already have the ability to do so. Now the second approach is...there, seems of course less flexible than the first option, but apart from that i don't have anything against it. The good thing is that the manager doesn't need to know all the objects that need to reset, so i can create new entities and register to those events ( and from this perspective, it seems flexible too).
Im concerned about the scalability and maintainability of those options in the future. Is there a "best practice" for doing this ? or is just "whatever fits yout project" ? Thanks.
My sincere apologies if this question doesn't meet the requirements to be asked on this site.