使用CORONA SDK点亮游戏

时间:2014-03-29 18:31:17

标签: loops lua corona

我正试图用CORONA SDK贬低一场熄灯游戏 但我无法找到循环它的方法! 要创建多少函数以及保持这种功能的方法 这是我的代码(它的假人,但朋友把它给了我,因为我正试图从那里开始)

obj = nil

px = 35
py = 50
r  = 22
xi = 60
yi = 60

x1y1 = display.newCircle(px+xi*0,py+yi*0,r) x1y1.id = "x1y1"
x2y1 = display.newCircle(px+xi*1,py+yi*0,r) x2y1.id = "x2y1"
x3y1 = display.newCircle(px+xi*2,py+yi*0,r) x3y1.id = "x3y1"
x4y1 = display.newCircle(px+xi*3,py+yi*0,r) x4y1.id = "x4y1"
x5y1 = display.newCircle(px+xi*4,py+yi*0,r) x5y1.id = "x5y1"

x1y2 = display.newCircle(px+xi*0,py+yi*1,r) x1y2.id = "x1y2"
x2y2 = display.newCircle(px+xi*1,py+yi*1,r) x2y2.id = "x2y2"
x3y2 = display.newCircle(px+xi*2,py+yi*1,r) x3y2.id = "x3y2"
x4y2 = display.newCircle(px+xi*3,py+yi*1,r) x4y2.id = "x4y2"
x5y2 = display.newCircle(px+xi*4,py+yi*1,r) x5y2.id = "x5y2"

x1y3 = display.newCircle(px+xi*0,py+yi*2,r) x1y3.id = "x1y3"
x2y3 = display.newCircle(px+xi*1,py+yi*2,r) x2y3.id = "x2y3"
x3y3 = display.newCircle(px+xi*2,py+yi*2,r) x3y3.id = "x3y3"
x4y3 = display.newCircle(px+xi*3,py+yi*2,r) x4y3.id = "x4y3"
x5y3 = display.newCircle(px+xi*4,py+yi*2,r) x5y3.id = "x5y3"

x1y4 = display.newCircle(px+xi*0,py+yi*3,r) x1y4.id = "x1y4"
x2y4 = display.newCircle(px+xi*1,py+yi*3,r) x2y4.id = "x2y4"
x3y4 = display.newCircle(px+xi*2,py+yi*3,r) x3y4.id = "x3y4"
x4y4 = display.newCircle(px+xi*3,py+yi*3,r) x4y4.id = "x4y4"
x5y4 = display.newCircle(px+xi*4,py+yi*3,r) x5y4.id = "x5y4"

x1y5 = display.newCircle(px+xi*0,py+yi*4,r) x1y5.id = "x1y5"
x2y5 = display.newCircle(px+xi*1,py+yi*4,r) x2y5.id = "x2y5"
x3y5 = display.newCircle(px+xi*2,py+yi*4,r) x3y5.id = "x3y5"
x4y5 = display.newCircle(px+xi*3,py+yi*4,r) x4y5.id = "x4y5"
x5y5 = display.newCircle(px+xi*4,py+yi*4,r) x5y5.id = "x5y5"

bb = {x1y1,x2y1,x3y1,x4y1,x5y1,x1y2,x2y2,x3y2,x4y2,x5y2,x1y3,x2y3,x3y3,x4y3,x5y3,x1y4,x2y4,x3y4,x4y4,x5y4,x1y5,x2y5,x3y5,x4y5,x5y5}
iClicked = 0

function click(e)
  if(e.phase == "ended") then
    --circleID = e.target.id
    --whichCircle()
    print(e.target.id)
    obj = e.target


    for u=1,25 do
      if(obj==bb[u]) then
        iClicked = u
      end
    end

    if((iClicked-5) > 0 and (iClicked-5) < 26) then
      bb[iClicked-5]:setFillColor(1,0,0)
    end

    if((iClicked-1) > 0 and (iClicked-1) < 26) then
      bb[iClicked-1]:setFillColor(1,0,0)
    end

    obj:setFillColor(1,0,0)

    if((iClicked+1) > 0 and (iClicked+1) < 26) then
      bb[iClicked+1]:setFillColor(1,0,0)
    end

    if((iClicked+5) > 0 and (iClicked+5) < 26) then
      bb[iClicked+5]:setFillColor(1,0,0)
    end    

  end
end

for k=1,25 do
  bb[k]:addEventListener("touch",click)
end

所有关于拥有25个圆圈并打开和关闭它们但它似乎对我不起作用 任何好的帮助都会很棒

由于

1 个答案:

答案 0 :(得分:2)

local myCircles = {}

for y = 1, 5 do
    myCircles[y] = {}
    for x = 1, 5 do
        myCircles[y][x] = display.newCircle(px+xi*0,py+yi*4,r)
        myCircles[y][x].id = .id = "x" .. x .. "y" .. y
    end
end

或类似的东西。 罗布