These are the listeners invoked inside scene:create in principal game composer scene.
Name of function and variables are often in italian, I hope you understand it.
I have set as comment not complete code in this topic.
[lua]
–//snake vector/–
local serpente={}
for i=lungSerp,1,-1 do
serpente[i] = creaScaglia(serpente[i])
gruppoSerpente:insert( serpente[i] )
end
---------------------------LISTENERS-----------------------------------------
–avvio(serpente)
vT = function() velocitaTesta(serpente,1,VX,VY); end
Runtime:addEventListener( “enterFrame”, vT )
vC=function() velocitaCoda(serpente); end
Runtime:addEventListener( “enterFrame”, vC )
–[[
mVm=function() movimento(serpente); end
Runtime:addEventListener(“enterFrame”, mVm )
aC=function() aggiornaCelle(serpente); end
Runtime:addEventListener(“enterFrame”, aC )
sV=function() svolta(serpente); end
Runtime:addEventListener(“enterFrame”, sV )
if opzioniControllo==0 then
aD = function() where=“dx”; end
areaDestra:addEventListener( “tap”, aD )
aS = function() where=“sx”; end
areaSinistra:addEventListener( “tap”, aS )
else
sfondo:addEventListener( “touch”, swipe )
end
if opzioniMuri==0 then
sM=function() scontroMargini(margineSx,margineDx,margineUp,margineDn,serpente) end
Runtime:addEventListener( “enterFrame”, sM )
else
cM=function() if stopGioco==0 then stopGioco=crashMargini(margineSx,margineDx,margineUp,margineDn,serpente) end end
Runtime:addEventListener( “enterFrame”, cM )
end
gC=function() gioco(serpente); end
Runtime:addEventListener(“enterFrame”, gC )
mS=function() morsoSerpente(serpente); end
Runtime:addEventListener(“enterFrame”, mS )
pG=function(event) pausa(serpente); return true; end
pauseGroup:addEventListener( “tap”, pG )
pS=function(event) play(serpente); return true; end
playShape:addEventListener( “tap”, pS )
homeShape:addEventListener( “tap”, ritornaCasa )
–]]
[/lua]
These are the function that moves head and body and the function that create the snake in other modules
[lua]
function creaScaglia(scaglia)
scaglia = display.newRect( 150 + margine, 150, 15, 15 )
scaglia.anchorX = 1
scaglia.anchorY = 1
scaglia:setFillColor( Rgb2,rGb2,rgB2 )
margine=margine+15
scaglia.xSvolta=1000
scaglia.ySvolta=1000
scaglia.ind=1
scaglia.stato=""
scaglia.direz=""
scaglia.xSegno=1*fasterVar
scaglia.ySegno=0*fasterVar
scaglia.NextxSegno=0
scaglia.NextySegno=0
scaglia.teleport=0
return scaglia
end
–snake moves–
function velocitaCoda(snake)
for i=#snake,2,-1 do
snake[i].x=snake[i].x+snake[i].xSegno
snake[i].y=snake[i].y+snake[i].ySegno
end
end
–head moves–
function velocitaTesta(snake,part,vx,vy)
snake[part].x=snake[part].x+vx
snake[part].y=snake[part].y+vy
snake[part].xSegno=vx;
snake[part].ySegno=vy;
end
[/lua]