Page 1 of 1

Match 3

Posted: Wed Mar 19, 2014 12:43 am
by greentiger
Is there a tutorial or sample game that will help me with a Match 3 type game?
Any help would be appreciated. Thanks.

Re: Match 3

Posted: Wed Mar 19, 2014 10:47 pm
by YGOFreak1997
You shall use the almighty power of Google! ^^

Re: Match 3

Posted: Sun Mar 23, 2014 5:43 am
by greentiger
YGOFreak1997 wrote:You shall use the almighty power of Google! ^^
I have. I haven't found anything. That's not really a helpful comment.
At best I've found dead links and tutorials not in English.
Also, I wouldn't have asked if I had found something elsewhere.

Re: Match 3

Posted: Sun Mar 23, 2014 7:21 am
by micha
You can find a series of tutorial for a match 3 game here. They are not for LÖVE, though, but for a different frame work, so I cannot say, if they are helpful.

If this tutorial does not help, people on the forum can still help you. In that case, please upload a .love file of what you have so far, and tell us where exactly you have problems.

Re: Match 3

Posted: Mon Mar 24, 2014 5:52 am
by greentiger
I will do my best, thanks for the direction.
My main background is writing stuff for PHP and webapps, it's different enough that it's often hard to know where to begin.

Re: Match 3

Posted: Thu Apr 03, 2014 9:33 pm
by greentiger
So if you were to do a match 3 game in say a 4x4 grid, with say 4 colors, would it better to use a flat array or is there another way available that's more efficient?

(0, 3, 2, 1,
4, 0, 2, 3,
0, 4, 1, 1,
0, 3, 1, 2)

also I could see a way to check if there are matches in a horizontal row, but horizontal would be a little harder.

Re: Match 3

Posted: Thu Apr 03, 2014 10:33 pm
by Sheepolution
I don't see any problems with using a flat array like that. But it might depend on how advanced you want to go?

To check matches, I'd do something like..

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

Re: Match 3

Posted: Fri Apr 04, 2014 12:35 am
by greentiger
OK, maybe because I'm tired but right now I'm just focusing on drawing the grid. It sort of works, but my math is obviously off. Can anyone please point out what I'm doing wrong? Thanks!

this is in grid.lua

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

EDIT: I fixed up the draw routine.

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

Re: Match 3

Posted: Fri Apr 04, 2014 7:18 pm
by greentiger
Mods: Please move this to the Support and Development.

I can draw the array now just fine and I have it looking decent.
Anyone know of an example program where I can look to see how to select the images/parts of the array to try to swap tiles?
Any idea one how to validate move choices?

That's what I'm working on right now and so far I haven't come up with an idea on how to do this.