This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi all, just wondered if yall could help me with this rotate method for my tetris game. This method works fine, but I want the points of the body of the pieces to stay positive, for example, if I rotate the "J" Piece once (90 degrees) it will rotate out of the standard 0,0 origin and actually have one of the blocks (points) sticking out of this quadrant.
Is there an easy way to implement the rotation around a central origin for EVERY piece, or a way to reset the origin after the piece has been moved?
I don't think that rotating around an object's center will necessarily prevent its points from straying into negative territory. For example, if we have a rectangle with vertices
its center is at
and rotating it 90 degrees clockwise would put it at
which has crossed the x-axis. So I think your best bet is to just rotate the shape like you're doing, but then shift it afterwards. To do this, you'll need to figure out the minimum x coordinate and minimum y coordinate after rotation. Then loop through and subtract minX from each x coord, and subtract minY from each y coord.
To do this, you will need at least one more loop besides the one you've written. But if you're clever, you can do this with only one more loop, by combining some steps into the loop you've already written. However if you're having trouble, don't hesitate to write as many loops as you need; they're pretty fast and easy. You can always figure out how to combine them later.
"I'm not back." - Bill Harding, Twister
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com