Math 3 destroy function

 I want to make a match 3 destroy function like this game  

https://www.youtube.com/watch?v=8Fnqg_vw094

I have no idea how to do that , is there any tutorial about Math 3 destroy function ?

local arr = {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0},} local text = {} local block = {} for i = 1 , 3 do text[i] = {} for j = 1 , 7 do text[i][j] = display.newText(arr[j][i], 100, 330, "",20) text[i][j].x = i \* 22 text[i][j].y = j\*22 end end num = 1 function newBlock() block[num] = display.newRect(0,0,40,40) block[num].x = 160 block[num].y = 100 block[num].id = 1 block[num].id2 = 2 block[num]:setFillColor(0.9,0.4,0.9) move(block[num]) end function move(obj) if obj.id \< 7 then if arr[obj.id+1][obj.id2] == 0 then obj.id = obj.id + 1 transition.to(obj,{time = 300 , y = obj.y + 41 , onComplete = function(self) local function move2() move(obj) end timer.performWithDelay(250,move2,1) end}) elseif obj.id-1 \> 0 then arr[obj.id][obj.id2] = 1 obj.id = 1 obj.id2 = 1 for i = 1 , 3 do for j = 1 , 7 do text[i][j].text = arr[j][i] end end newBlock() else arr[obj.id][obj.id2] = 1 obj.id = 1 obj.id2 = 1 for i = 1 , 3 do for j = 1 ,7 do text[i][j].text = arr[j][i] end end end else arr[obj.id][obj.id2] = 1 obj.id = obj.newId obj.id2 = 3 for i = 1 , 3 do for j = 1 ,7 do text[i][j].text = arr[j][i] end end newBlock() end end newBlock()

Check out my game Bombaroo! on the App Store or Google Play - it’s a free download, no worries. If that’s what you need I can share the “detect 3 similar blocks” code with you!

Cheers,

Thomas

Okay, there’s bad news and good news! :wink:

The bad news is, I don’t have the time to explain how my code works, sorry 'bout that. The good news is: here’s my code!

local popTable = {} for ct = 1, 30 do if (ct-1)%5 \< 3 then -- no need to check past 3rd column for row match if (Array[ct] == Array[ct+1]) and (Array[ct] == Array[ct+2]) then pop1 = { 0, 1, 2} for a = 1, 3 do table.insert(popTable, #popTable+1, ct+pop1[a]) end end end if (ct \< 21) then --no need to check past 4th row for column match if (Array[ct] == Array[ct+5]) and (Array[ct] == Array[ct+10]) then pop2 = { 0, 5, 10} for a = 1, 3 do table.insert(popTable, #popTable+1, ct+pop2[a]) end end end end --sort table table.sort(popTable) ---unique table, removes double entries from table local newTable = {} local lastNumber = 0 for ct = 1, #popTable do nextNumber = popTable[ct] if (nextNumber ~= lastNumber) then newTable[#newTable+1] = nextNumber end lastNumber = nextNumber end local blocksDestroyed = #newTable -- build Array with 1s where blocks match CheckArray = {} for i = 1, 30 do CheckArray[i] = 0 end for i = 1, #newTable do CheckArray[newTable[i]] = 1 end -- CheckArray table is now filled with 0s where nothing is found and 1s where matches of 3 are found! -- Now evaluate checkarray: Did something match??? local matchFound = false for i = 1, 30 do if (CheckArray[i] == 1) then matchFound = true end end

By the way, this checks for a combination of 3 or more (4, 5 or 6) in a row or column.

Check out my game Bombaroo! on the App Store or Google Play - it’s a free download, no worries. If that’s what you need I can share the “detect 3 similar blocks” code with you!

Cheers,

Thomas

Okay, there’s bad news and good news! :wink:

The bad news is, I don’t have the time to explain how my code works, sorry 'bout that. The good news is: here’s my code!

local popTable = {} for ct = 1, 30 do if (ct-1)%5 \< 3 then -- no need to check past 3rd column for row match if (Array[ct] == Array[ct+1]) and (Array[ct] == Array[ct+2]) then pop1 = { 0, 1, 2} for a = 1, 3 do table.insert(popTable, #popTable+1, ct+pop1[a]) end end end if (ct \< 21) then --no need to check past 4th row for column match if (Array[ct] == Array[ct+5]) and (Array[ct] == Array[ct+10]) then pop2 = { 0, 5, 10} for a = 1, 3 do table.insert(popTable, #popTable+1, ct+pop2[a]) end end end end --sort table table.sort(popTable) ---unique table, removes double entries from table local newTable = {} local lastNumber = 0 for ct = 1, #popTable do nextNumber = popTable[ct] if (nextNumber ~= lastNumber) then newTable[#newTable+1] = nextNumber end lastNumber = nextNumber end local blocksDestroyed = #newTable -- build Array with 1s where blocks match CheckArray = {} for i = 1, 30 do CheckArray[i] = 0 end for i = 1, #newTable do CheckArray[newTable[i]] = 1 end -- CheckArray table is now filled with 0s where nothing is found and 1s where matches of 3 are found! -- Now evaluate checkarray: Did something match??? local matchFound = false for i = 1, 30 do if (CheckArray[i] == 1) then matchFound = true end end

By the way, this checks for a combination of 3 or more (4, 5 or 6) in a row or column.