我正在构建俄罗斯方块并尝试考虑如何旋转碎片.
它们是在一个块上旋转吗?或者他们应该变形......也就是交换位置?

我正在考虑这样做的方式是硬编码......就像(伪代码):
if (rotateRight()) {
if (Piece == "T") {
if (Piece.getCurrRotation() == down (aka.. 180 degrees))
move each Tile in Piece from the down rotation to the left rotation... each coordinate would be pre-specified for a given condition... aka lot's of hardcoding
}
if (Piece == "L") { etc...
}
}
if (rotateLeft()) {
perform same checks for the Left...
}
Run Code Online (Sandbox Code Playgroud)
但这似乎是一个庞大的代码量只是为了弄清楚
首先)当前作品处于哪个旋转位置(每个作品有4个可能的旋转)
其次)从那里...根据该片段将其设置为新的硬编码坐标
我必须为每件作品做到这一点......这似乎是错误的思考方式.
还有其他想法吗?
对于每个 PieceType 对象,我可能会有 1-4 个 Orientation 对象。然后,每个方向将定义实际块的位置(相对于某个枢轴)。例如
PieceType "L":
Orientation 1:
#
#
##
Orientation 2:
###
#
Orientation 3:
##
#
#
Orientation 4:
#
###
PieceType "I":
Orientation 1:
#
#
#
#
Orientation 2:
####
Run Code Online (Sandbox Code Playgroud)
每个 PieceType 还可以保存有关每个可能的“方向变化”(即旋转)所需空间的信息。这些都是静态信息,因此在游戏过程中实际上不需要移动方块。只需更改块的方向,然后让方向对象告诉您块的位置。
| 归档时间: |
|
| 查看次数: |
3133 次 |
| 最近记录: |