Rotating Tetris Piece

BlitzMax Forums/BlitzMax Beginners Area/Rotating Tetris Piece

I've solved it, if anybody's interested.

	Method rotate(game:TGame, factor:Int=1)
		'This method rotates the shape by 90 degrees factor times clockwise
		'about its pivot (point 0, 0)
		'For example factor=1 means 90 degree clockwise rotation
		'factor=-1 conterclockwise 90
		
		'to avoid redundant rotations. yay the complicatedness
		factor = ((factor < 0) * 4 + factor) Mod 4;
		
		'if the piece cannot be rotated (square), or no rotation is requested(!) then return
		If Not rotatable Or factor = 0 Then Return;
		
		'create some new points to store the rotated piece
		Local newPoint:TPoint[] = New TPoint[pointnum];
		For Local i:Int = 0 Until pointnum
			newPoint[i] = New TPoint;
		Next
		
		'store the current points in a temp array
		Local tempPoint:TPoint[] = New TPoint[pointnum];
		For Local i:Int = 0 Until pointnum
			tempPoint[i] = point[i].clone();
		Next
		
		'rotate the piece by swapping X and Y and changing the appropriate sign
		For Local rotationCount:Int = 0 Until factor
			For Local i:Int = 0 Until pointnum
				newPoint[i].alive = tempPoint[i].alive;
				newPoint[i].x = -tempPoint[i].y;
				newPoint[i].y = tempPoint[i].x;
				tempPoint[i] = newPoint[i].clone();
			Next
		Next
		
		'remove the old piece from the game board
		pluckPiece(game);
		
		'in case the piece cannot be rotated here, store the old points safely. then give the piece the new rotated points
		Local oldPoint:TPoint[] = New TPoint[pointnum];
		For Local i:Int = 0 Until pointnum
			oldPoint[i] = point[i].clone();
			point[i] = newPoint[i].clone();
		Next
		
		'attempts to place the rorated piece. returns false if cannot be rotated. in that case restore the old points and replace
		If Not placePiece(game, originX, originY)
			For Local i:Int = 0 Until pointnum
				point[i] = oldPoint[i].clone();
			Next
			placePiece(game, originX, originy);
		End If
	End Method