centerRow = fallingPieceRow + numFallingPieceRows//2We actually have two pieces: the old falling piece (before the rotation), and the new falling piece (after the rotation). We can compute each of their centers as such:
oldCenterRow = oldRow + oldNumRows//2 newCenterRow = newRow + newNumRows//2Note that oldNumRows and newNumRows are not the same, since the dimensions change when the piece is rotated. In any case, to keep the old and new centers the same, we just set oldCenterRow equal to newCenterRow in the equations above.
oldRow + oldNumRows//2 = oldCenterRow = newCenterRow = newRow + newNumRows//2Then we solve for newRow in this new equation, which gives us:
newRow = oldRow + oldNumRows//2 - newNumRows//2We then repeat for the column, and we're done!
David Kosbie |