I don’t see you using the rotate() command anywhere in your code – just moving things left, right, up and down.
Have you looked at the rotate command?
Have you read the tutorial on 2D Transformations, which covers how to rotate things?
Edit: …ah, I see, by “rotated” you mean swapping the width and height variables to create a 90-degree effect, rather than actually rotating.