Match 3

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
greentiger
Prole
Posts: 16
Joined: Tue Mar 11, 2014 6:48 pm
Location: united states

Match 3

Post 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.
User avatar
YGOFreak1997
Party member
Posts: 103
Joined: Sun Jan 22, 2012 4:29 pm
Location: Germany, Baden-Württemberg
Contact:

Re: Match 3

Post by YGOFreak1997 »

You shall use the almighty power of Google! ^^
Also look at my LÖVE-Tutorial-Youtube-Channel (German ^^)
GitHub Repo: Click Me!
Website: No, Me!
IndieDB: Or Maybe Me?

ÖBEY!
greentiger
Prole
Posts: 16
Joined: Tue Mar 11, 2014 6:48 pm
Location: united states

Re: Match 3

Post 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.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Match 3

Post 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.
greentiger
Prole
Posts: 16
Joined: Tue Mar 11, 2014 6:48 pm
Location: united states

Re: Match 3

Post 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.
greentiger
Prole
Posts: 16
Joined: Tue Mar 11, 2014 6:48 pm
Location: united states

Re: Match 3

Post 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.
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: Match 3

Post 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
greentiger
Prole
Posts: 16
Joined: Tue Mar 11, 2014 6:48 pm
Location: united states

Re: Match 3

Post 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
greentiger
Prole
Posts: 16
Joined: Tue Mar 11, 2014 6:48 pm
Location: united states

Re: Match 3

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests