gdquest-demos / godot-platformer-2d

2d Metroidvania-inspired game for the 2019 GDquest Godot Kickstarter course project.
MIT License
608 stars 71 forks source link

Review how States pass messages to one another #153

Open NathanLovato opened 5 years ago

NathanLovato commented 5 years ago

I've been thinking about these transition problems a bit and the way we pass values around from state to state to preserve state can be improved. At the moment we use the msg Dictionary with arbitrary variables and rely on each state to know what to do with it.

I think we're at a point where we could introduce a player/hook state Dictionary that's internally kept in each state we create and it's passed around when transitioning form one state to the other. This way it would be less of a hassle to correctly set say velocity after hook is used when hitting the ground. Not only that, but it would make save/load simpler too.

We could also have partial state updates from state to state, for example if the death state doesn't affect velocity (which shouldn't) then we just pass relevant Dictionary parts to it and not the entire variable.

This internal state that represents all variables affecting the player/hook at any one point, like velocity, etc could be thought of like the "contract" that the states use and it possibly simplifies keeping track of changes made (from dev. point of view)

Originally posted by @razcore-art in https://github.com/GDquest/godot-metroidvania-2d/issues/150#issuecomment-519475432

NathanLovato commented 5 years ago

I'll still start the player char controller course with what we have, as we already have some pretty solid code. But it makes sense.

NathanLovato commented 4 years ago

@razcore-art is this still relevant? Have you had the opportunity to give this more thought?