A heat engine is a device that converts heat into mechanical motion that can be used to do work . Many kinds of real heat engines have been invented like the internal combustion engine that drives cars and the steam engine that once powered ships and trains . Also the stirling engine is a heat engine .