I am making a program similar to the famous game Tetris and I’ve run into some problems when it comes to rotating a block.
I know you are able to rotate figures in a coordinate system by using “x = -y” and “y = x” but the problem is that because I am using an array of integers to represent the block it makes things so much more difficult.
My array looks like:
int[][] space = new int[20][10];
And if a coordinate contains a block the value is 1 else it’s 0.
So how can I rotate a block in that space without getting trouble with negative numbers?
Here’s a sample piece (reusing your int[][] using 0’s and 1’s, which might as well be done using a boolean array):
You can rotate a piece doing this:
The starting piece:
Here’s rotate(piece):
Here’s rotate(rotate(piece)):
And here’s rotate(rotate(rotate(piece))):