Here is the source code, I used godot, and c#, but it's easy to translate to gdscript. I only use godot for this, so I don't remember much, I don't even have godot installed to open the project.
If I remember correctly, in the player script there is a function to calculate the energy, I think it was an exponential function, but I have been trying until the sensation was pleasant, although surely it can be refined much more.
Now I don't remember if I have used FSM (finite state machine) if so, look at the JumpingState script file.