gdquest-demos / godot-platformer-2d

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

After a hook, after falling on the ground, run doesn't preserve momentum #150

Closed NathanLovato closed 5 years ago

razcore-rad 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)