Here's how to beat the boss.
He will pass by either on the top, or on the bottom, with his mouth closed. That place will be safe when he passes by the next time with his mouth open. After he passes by go back to the middle and see where he is going with his mouth closed the next time and go there.