This is pretty impressive for someone just starting out. You seem to have an intuitive understanding of geometry. However, there is some knowledge about domains that you may not know about because of how much education you had.
In physics, the correct system of equations describing motion:
1. speed = change_in_location / time 2. acceleration = change_in_speed / time
Note. Here I use the word "speed" because it is shorter than "speed". The correct word is technically "speed." In physics, speed means something a little different from speed.
Another thing you need to know about is that gravity is a form of acceleration. In particular, this acceleration down 9.8 m / s / s
So, we rewrite all of the above:
new_location = (speed * time) + old_location new_speed = (acceleration * time) + old_speed
If you accept an animation loop with constant time, you can assume that time = 1. Thus, this simplifies it:
new_location = speed + old_location new_speed = acceleration + old_speed
This is enough to simulate gravity. Since gravity is just acceleration:
gravity = SOME_NUMBER;
To jump, just give the object an instant increase in speed:
// jump: kingYSpeed = -SOME_OTHER_NUMBER; // negative because "up"
Note. Domain knowledge is knowledge outside of programming that a programmer must understand in order to solve a specific problem. For example, a programmer who writes accounting software must have some knowledge of accounting. In practice, not all programmers in the industry make an effort to acquire domain knowledge, because sometimes there is a systems analyst / consultant writing software requirements. But when you write your own software, you have no choice but to acquire some domain knowledge.