0,]']>S}Wup8d%qy)6o;]AsVl31 then cx=cx-1 sfx(17,nil,-1,1) end end if btnp(3) then if cx<5 then cx=cx+1 sfx(17,nil,-1,1) end end if btnp(4) then shiftleft() end if btnp(5) then shiftright() end checkformatch() fillemptyspaces() spawntimer=spawntimer-1 if spawntimer==0 then spawntimer=120-(score//4) dospawn() end else locktimer=locktimer-1 doexplosionanim() end cls(0) print(score,0,0) drawgrid(80,12) t=t+1 end function drawgrid(x,y) rect(x,y,80,112,1) for gy=1,7 do for gx=1,5 do if gy==4 then spr((grid[gy][gx]*2),x+((gx-1)*16),y+((gy-1)*16),0,1,0,0,2,2) if gx==cx then spr(12,x+((gx-1)*16),y+((gy-1)*16),0,1,0,0,2,2) end else spr((grid[gy][gx]*2),x+((gx-1)*16),y+((gy-1)*16),0,1,0,0,2,2) end end end end function shiftleft() local ti=grid[4][1] table.remove(grid[4],1) table.insert(grid[4],ti) sfx(16,nil,-1,1) end function shiftright() local ti=grid[4][5] table.remove(grid[4],5) table.insert(grid[4],1,ti) sfx(16,nil,-1,1) end function shiftup() grid[1][cx]=grid[2][cx] grid[2][cx]=grid[3][cx] grid[3][cx]=grid[4][cx] grid[4][cx]=grid[5][cx] grid[5][cx]=grid[6][cx] grid[6][cx]=grid[7][cx] grid[7][cx]=0 end function shiftdown() grid[7][cx]=grid[6][cx] grid[6][cx]=grid[5][cx] grid[5][cx]=grid[4][cx] grid[4][cx]=grid[3][cx] grid[3][cx]=grid[2][cx] grid[2][cx]=grid[1][cx] grid[1][cx]=0 end function checkformatch() local mr=grid[4] for x=1,5 do if mr[3]==x then -- match 5 if (mr[1]==x and mr[2]==x and mr[4]==x and mr[5]==x) then mr[1]=16 mr[2]=16 mr[3]=16 mr[4]=16 mr[5]=16 score=score+15 sfx(21,nil,-1,1) locktimer=20 animtimer=4 end -- match 4 if (mr[1]==x and mr[2]==x and mr[4]==x) then mr[1]=16 mr[2]=16 mr[3]=16 mr[4]=16 score=score+8 sfx(20,nil,-1,1) locktimer=20 animtimer=4 end if (mr[2]==x and mr[4]==x and mr[5]==x) then mr[2]=16 mr[3]=16 mr[4]=16 mr[5]=16 score=score+8 sfx(20,nil,-1,1) locktimer=20 animtimer=4 end -- match 3 if (mr[1]==x and mr[2]==x) then mr[1]=16 mr[2]=16 mr[3]=16 score=score+3 sfx(19,nil,-1,1) locktimer=20 animtimer=4 end if (mr[2]==x and mr[4]==x) then mr[2]=16 mr[3]=16 mr[4]=16 score=score+3 sfx(19,nil,-1,1) locktimer=20 animtimer=4 end if (mr[4]==x and mr[5]==x) then mr[3]=16 mr[4]=16 mr[5]=16 score=score+3 sfx(19,nil,-1,1) locktimer=20 animtimer=4 end end end end function doexplosionanim() if animtimer==0 then animtimer=4 for y=1,7 do for x=1,5 do if grid[y][x]==16 then grid[y][x]=17 elseif grid[y][x]==17 then grid[y][x]=18 elseif grid[y][x]==18 then grid[y][x]=19 elseif grid[y][x]==19 then grid[y][x]=0 end end end else animtimer=animtimer-1 end end function fillemptyspaces() for x=1,5 do if grid[4][x]==0 then if grid[3][x]~=0 then --or math.random(4)~=4 then grid[4][x]=grid[3][x] grid[3][x]=grid[2][x] grid[2][x]=grid[1][x] grid[1][x]=0 else if grid[5][x]~=0 then --or math.random(4)~=4 then grid[4][x]=grid[5][x] grid[5][x]=grid[6][x] grid[6][x]=grid[7][x] grid[7][x]=0 else grid[4][x]=math.random(5) end end end end end function dospawn() if checkforfreetiles() then local c=math.random(5) local l=math.random(2) -- spawn on top for x=1,3 do if l==1 then if grid[4-x][c]==0 then grid[4-x][c]=math.random(5) sfx(18,nil,-1,1) break end end if l==2 then if grid[4+x][c]==0 then grid[4+x][c]=math.random(5) sfx(18,nil,-1,1) break end end end else trace("GAME OVER!\nYour score: "..score) exit() end end function checkforfreetiles() for y=1,7 do for x=1,5 do if grid[x][y]==0 then return true end end end return false end