Match 3
Posted: Wed Mar 19, 2014 12:43 am
Is there a tutorial or sample game that will help me with a Match 3 type game?
Any help would be appreciated. Thanks.
Any help would be appreciated. Thanks.
I have. I haven't found anything. That's not really a helpful comment.YGOFreak1997 wrote:You shall use the almighty power of Google!
Code: Select all
function getMatches(blocks)
local t
for i,v in ipairs(blocks) do
t = {}
if blocks[i-1] == v then
table.insert(t,i-1)
end
if blocks[i+1] == v then
table.insert(t,i-1)
end
if blocks[i-length] == v then
--length is how many blocks a row has.
table.insert(t,i-1)
end
if blocks[i+length] == v then
table.insert(t,i-1)
end
end
if #t > 3 then
return t
end
return false
end
Code: Select all
gridxOffset = 0
gridyOffset = 0
gridxPadding = 4
gridyPadding = 4
tilesxWidth = 48
tilesyWidth = 48
function gridPickTile()
-- picks between 6 different tiles
end
function gridLoad()
gridArr = {}
for i = 0, 63, 1 do
gridArr[i] = gridPickTile()
end
end
function gridDraw()
-- math.fmod(x,y) returns remainder of x/y and rounds to zero
local drawx = 0
local drawy = 0
local gridrow = 0
local gridcol = 0
for i = 0, 63, 1 do
drawx = gridxOffset + (gridcol * (gridxPadding + tilesxWidth))
drawy = gridyOffset + (gridrow * (gridyPadding + tilesyWidth))
love.graphics.draw(gridArr[i], drawx, drawy)
if gridcol >= 7 then
gridcol = 0
else
gridcol = gridcol + 1
end
if math.fmod(i, 7) == 0 then
gridrow = gridrow + 1
end
end
end
Code: Select all
function gridDraw()
-- math.fmod(x,y) returns remainder of x/y and rounds to zero
local drawx = 0
local drawy = 0
local gridrow = 1
local gridcol = 1
for i = 0, 63, 1 do
drawx = gridxOffset + ((gridcol * (gridxPadding + tilesxWidth)) - tilesxWidth)
drawy = gridyOffset + ((gridrow * (gridyPadding + tilesyWidth)) - tilesyWidth)
love.graphics.draw(gridArr[i], drawx, drawy)
if gridcol >= 8 then
gridcol = 1
else
gridcol = gridcol + 1
end
if math.fmod(i + 1, 8) == 0 then
gridrow = gridrow + 1
end
end
end