我有一段代码可以在俄罗斯方块游戏中旋转一块,但我不知道 xOffset 和 yOffset 变量的含义。你能为我解释更多吗?非常感谢 !!
双 xOffset = 宽度/2.0 - .5;双 yOffset = 高度/2.0 - .5;
//Create a new body
TPoint[] newBody = copyBody(body);
for(TPoint p : newBody){
//Rotoate 90 degrees counter clockwise about the origin
double newX = p.x;
double newY = p.y;
newX -= xOffset;
newY -= yOffset;
double temp = newX;
newX = -newY;
newY = temp;
newX += yOffset;
newY += xOffset;
p.x = (int) newX;
p.y = (int) newY;
}
return new Piece(newBody);