When the user presses the "orbit" button, store the vector between the ship and the planet. On every update, change the vector's angle leaving magnitude the same and then update the ships position by adding the planets position and the vector pointing at the ships new position. This will create the effect of the ship moving in a uniform circle around the object being orbited.
Also, it would be a nice touch if you programmed the ship to slowly turn until it was pointed 90 degrees to the planet before starting the uniform orbit, otherwise the ship could be going straight toward it then sharply turn into orbit when the user presses the button.
More Detailed Physics
If you want more complicated things like true elliptical orbits and correct orbital speeds, you will need to do some research into real physics.
This question has already been asked: https://stackoverflow.com/questions/4038554/2d-orbital-physics; But for those that find this page, I will summarize the results and try to apply it to your situation and somewhat explain the physics.
His engine uses the following equation to calculate the force applied on both objects, where F
is the force, G
is the gravitational constant, m
and M
are the masses of the two objects, and finally r
is the radius.
F = G M m / r^2
Remember that Newton's Third Law says that "all forces between two objects exist in equal magnitude and opposite direction", meaning that this equation is evaluated once and represents both forces present.
In addition, his pseudo code for his engine might be helpful:
for each time step of length t:
reset cumulative forces on each object to 0.
for each unique pair of objects:
calculate force between them due to gravity.
accumulate force to the two objects.
for each object:
calculate velocity change dV for this timestep using Ft / m.
v = v + dV.
calculate position change dS using v * t.
s = s + dS.
Also, he discovered that he needed to normalize the direction vector before he applied it to the force.