A customer of mine has a bed which folds way and allows his son to have table which pops up as the bed folds away. In the process the table stays horizontal at all times.
Here is a DIY version
Here is a DIY version
How to Build a Murphy Bed that Easily Transforms into a Desk
This bed quickly converts to a desk without increasing its footprint. When you switch it back to a bed, the desk stays level, so you can leave all your stuff on it!
www.familyhandyman.com