我是中级统一开发人员,仍处于学习曲线的进展中。我坚持使用变换游戏对象。我知道它有位置,旋转和比例属性,但是,我正在追踪一个俄罗斯方块克隆来扩大我的技能,我真的很难理解。请,不要认为这只是俄罗斯方块游戏,我有困难时期这种情况与二维网格系统的游戏。
我将在下面分享一种代码,我真的不完全理解正在发生的事情,但只是本能的未知。
开发人员遵循创建Transform [,]网格数组并尝试将块数据分配给此网格阵列的步骤,而不是根据移动块等更新网格。但是我无法理解代码中发生了什么,因为我无法用这个过程来塑造我的想法。
这里的代码示例;
// will be called from tetromino script
public void UpdateGrid(Tetromino tetromino)
{
for (int y = 0; y < gridHeight; y++)
{
for (int x = 0; x < gridWidth; x++)
{
// if there is a current existing tetromino in the grid coordinate
if (grid[x, y] != null) // registered mino at this position
{
// check to is if the tetromino is there
// if the parent transform is the tetromino transform that is send as parameter
if (grid[x,y].parent == tetromino.transform)
{
grid[x, y] = null; // updating the grid
}
}
}
}
// updates our grid
foreach (Transform mino in tetromino.transform)
{
Vector2 pos = Round(mino.position);
if (pos.y < gridHeight)
{
// storing mino with transform in that position
grid[(int)pos.x, (int)pos.y] = mino;
}
}
}
在此代码示例中,我需要了解什么?网格代表什么?一个点?一个空的游戏对象?这里发生了什么?
他是否将变换“mino”指定为mino块对象的引用?
我真的很难使用变换网格系统和许多类型的游戏,如2048或破碎游戏,或俄罗斯方块游戏等都有这种网格系统。
你能帮我理解变换网格和场景中的mino块之间的关系吗?
我真的很想学习游戏开发并花费很多时间来学习游戏。我感觉自己正在发展,但有时我在路上遇到了困难。网格系统对于跟踪游戏中的移动对象或块非常重要,我希望对它有一个纯粹的理解。
好的混淆术语会增加你的困惑。
在它的脑海中,它有一个名为grid的数组,用于计算事物是否可以移动 - 虽然你没有显示网格是如何定义的,但它将如何定义,因此很可能是Transform [,] grid = new Transform [x,y]其中x和y是网格的大小,它根据代表游戏区域的物理网格的宽度和高度来考虑。
简而言之,Transform mino in tetromino.transform
得到了所有的儿童成分,并逐渐通过它们在俄罗斯方块中它通常被称为4块,使得俄罗斯方块形状被称为mino's,最终的形状是Tetromino,请参阅https://en.wikipedia.org/wiki/Tetromino
使用数组来决定所有方块是否可以向下移动1,比试图移动一个对象更容易,并且统一判断它是否适合。