table結構
-- 游戲方塊
self.blocktype = {
{
{1, 1, 0},
{0, 1, 1}
},
{
{1, 1},
{1, 1}
},
{
{1, 0},
{1, 0},
{1, 1}
},
{
{0, 1, 0},
{1, 1, 1}
}
}
-- 方塊的旋轉
-- 方塊旋轉
function Login:Rotation(index)
self.count = self.count or 0
local a = {}
-- 旋轉90度
if(self.count == 0) then
for i = 1, #self.blocktype[index] do
a[i] = {}
for j = 1, #self.blocktype[index][i] do
a[i][j] = self.blocktype[index][2-j][i]
end
end
self.count = self.count + 1
return a
end
local b = {}
-- 旋轉180度
if(self.count == 1) then
for i = 1, #self.blocktype[index] do
b[i] = {}
for j = 1, #self.blocktype[index][j] do
b[i][j] = self.blocktype[index][2-i][3-j]
end
end
self.count = self.count + 1
return b
end
local c = {}
-- 旋轉270度
if(self.count == 2) then
for i = 1, #self.blocktype[index] do
c[i] = {}
for j = 1, #self.blocktype[index][j] do
c[i][j] = self.blocktype[j][3-i]
end
end
self.count = self.count + 1
return c
end
if(self.count == 3) then
return self.blocktype
end
end
這樣一直報錯不知道怎么改了
uj5u.com熱心網友回復:
俄羅斯方塊嗎?你的代碼太亂,隨便看了一下,就發現,如果我沒想錯,你的索引肯定是有問題的,lua的索引是從1開始的,你里面一些2-i,基本就認定越界了。
用一個比較直白,并且靠譜,以及健壯的作法,是定義方塊的四個方向的所有形態表現存下來。然后只存方塊型別ID,方塊的位置(可以以方塊的(0,0)位置來認為方塊的位置),以及方塊的轉向就可以描述當前的狀態了。
最后嘛,吐槽一下,高中生,大學生的程式作業才會這么寫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/23850.html
標籤:Unity3D
