if floormap[level][blockpos[2]][blockpos[1]]==0or floormap[level][blockpos[4]][blockpos[3]]==0ornot floormap[level][blockpos[4]][blockpos[3]]ornot floormap[level][blockpos[2]][blockpos[1]]then
done =true
win =false
end
elseif key==38then
blockpos[1]= blockpos[1]-1
blockpos[3]=blockpos[3]-1
moves = moves+1
if up then
up =false
blockdir=1
blockpos[1]=blockpos[1]-1
blockpos[3]=blockpos[1]+1
blockpos[4]=blockpos[2]
elseif blockdir==1then
up =true
blockpos[3]=blockpos[1]
blockpos[4]=blockpos[2]
end
if floormap[level][blockpos[2]][blockpos[1]]==0or floormap[level][blockpos[4]][blockpos[3]]==0ornot floormap[level][blockpos[4]][blockpos[3]]ornot floormap[level][blockpos[2]][blockpos[1]]then
done =true
win =false
end
elseif key==28then
blockpos[2]=blockpos[2]-1
blockpos[4]=blockpos[4]-1
moves = moves+1
if up then
up =false
blockdir=2
blockpos[2]=blockpos[2]-1
blockpos[3]=blockpos[1]
blockpos[4]=blockpos[2]+1
elseif blockdir==2then
up =true
blockpos[3]=blockpos[1]
blockpos[4]=blockpos[2]
end
if blockpos[1]<16and blockpos[1]>0and blockpos[2]<11and blockpos[2]>0then
if floormap[level][blockpos[2]][blockpos[1]]==0or floormap[level][blockpos[4]][blockpos[3]]==0ornot floormap[level][blockpos[4]][blockpos[3]]ornot floormap[level][blockpos[2]][blockpos[1]]then
done =true
win =false
end
else
done =true
win=false
end
elseif key==37then
blockpos[2]=blockpos[2]+1
blockpos[4]=blockpos[4]+1
moves = moves+1
if up then
up =false
blockdir=2
blockpos[3]=blockpos[1]
blockpos[4]=blockpos[2]+1
elseif blockdir==2then
up =true
blockpos[2]=blockpos[2]+1
blockpos[3]=blockpos[1]
blockpos[4]=blockpos[2]
end
if blockpos[2]>10or blockpos[4]>10then
gmeover =true
else
if floormap[level][blockpos[2]][blockpos[1]]==0or floormap[level][blockpos[4]][blockpos[3]]==0ornot floormap[level][blockpos[4]][blockpos[3]]ornot floormap[level][blockpos[2]][blockpos[1]]then
done =true
win =false
falling =true
end
end
end
if blockpos[1]<16and blockpos[1]>0and blockpos[2]<11and blockpos[2]>0then
for m=0,floormap[level][12]-1do
if floormap[level][floormap[level][13+m][2]][floormap[level][13+m][1]]==3then
if blockpos[1]==floormap[level][13+m][1]and blockpos[2]==floormap[level][13+m][2]or blockpos[3]==floormap[level][13+m][1]and blockpos[4]==floormap[level][13+m][2]then
button =true
for l=1,floormap[level][13+m][3]do
if floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==0and floormap[level][13+m][4+2*floormap[level][13+m][3]]==1then
if blockpos[1]==floormap[level][13+m][1]and blockpos[2]==floormap[level][13+m][2]and blockpos[3]==floormap[level][13+m][1]and blockpos[4]==floormap[level][13+m][2]then
for l=1,floormap[level][13+m][3]do
if floormap[level][floormap[level][13+m][3+2*l-1]][floormap[level][13+m][3+2*l]]==0then
if floormap[level][blockpos[2]][blockpos[1]]==5and floormap[level][blockpos[4]][blockpos[3]]==5and blockpos[1]==blockpos[3]and blockpos[2]==blockpos[4]then
done=true
win=false
falling=true
end
end
if blockpos[1]==floormap[level][11][1]and blockpos[2]==floormap[level][11][2]and up then
done=true
win=true
end
else
done =true
win =false
moves = moves +1
end
else
if key==38then
ifnot leftscroll then
leftscroll =true
elseif level>2and leftscroll then
leftscroll =false
end
end
if key==27then
ifnot rightscroll then
rightscroll =true
elseif level<=14and rightscroll then
rightscroll =false
end
end
end
end
end
function ontabKey()
zmg.clear()
if game then
game =false
zmg.fastCopy()
else
level = levelreached
zmg.fastCopy()
end
end
function onenterKey()
if game then
if done and win then
level=level+1
if level>levelreached then
levelreached = level
end
onNewLevel()
--var.store("levelreached",levelreached)
end
if done andnot win then
--var.store("levelreached",levelreached)
end
zmg.fastCopy()
else
game =true
zmg.fastCopy()
end
end
function drawTile(x1, x2, xoff, y1, y2, yoff, tcreset)