Well, I need to rotate an entity, depending on its moving direction (only X and Y). Picture explains better I think

So entity is moving in some direction and I just don't get how to rotate it in right angle :\ Ofc I can do that right if it moves along exactly X or exactly Y axis. But how to make it depending on its velocity?