Can you paint the engine bay with the engine still installed?

I am just starting to toy around with the idea of painting my car. The problem is what to do with the engine bay if i paint it a differnt color? A buddy of mine said there should I'm be a way to cover the engine and paint around it. Im not real convinced of that, however pulling the engine just seems like a pain.

Has anyone tried this?

Thanks!