Difficult bosses are the name of the game here!
In the case of Eggman in Green Grove 2 it's all a matter of spacing.
Just look at how the ball bounces, and try to always stay on the same side so that Robotnik shoots the metal ball on a similar trajectory every time.