I need Match-3 game mechanic



For some reason, my chips are overlapping, and the matches aren’t working very well.

I had a go this morning. I just did the drag and swap bit.

match3

edit - ive just digested your code a bit more
youve set the array up differently to me. Ive just used one object and four animations
i didnt use drag behaviour - i dont think you need to use it.
what im doing is the contents of the array have .id that relates to the object id and .ani that relates to the object animation index.
when touch starts on an object set ‘movefrom’ to the id of the object. save touch x,y
touch is on new fruit and fruit is less than 100pix from saved x,y set ‘moveto’ to fruit.id
when ‘swap’ is true. swap ‘movefrom’ and ‘moveto’ in the array and the id’s and ani’s of the fruit.
and then tween the fruit to their positions in the array
i created the array and objects in a repeat at the start. I hid the top row as i was going to use that when they fall (doh as i typed that i realised that i forgot to have the 'is visible condition!)
For the check algorithm i would scan the array in two directions and if the .ani (relating to the objects animation index)in the array doesn’t change as you scan add 1 and then check if 3 at the end of each row scan. But the scan algorithm would take me a while but i could do it if you’re stuck!

Why are you using an array? You have objects on screen in a grid, and you know which one has been dropped. There’s no need to iterate over the whole grid to see if there’s a line of 3. Just do a few checks around the dropped one.

its a personal thing i think . I just find the logic easier. It should run quicker too (not that it really matters with a game like this). I did do the match three logic this morning as i was curious but only done it horizontally so far. The difficult bit was the chain of falling. there’s a chain of check delete check tween repeat if one deleted that was hard to get right.
match3b

That looks like a simpler version of candy crush :laughing:

Its just a match 3 thing - bejeweled etc. I’ve done the algorithm to check vertically now and updated the game - see link!
you cant make a move while they’re falling at the moment and I dont create any new ones at the moment
what i didnt do was check for 4 or 5 in a row and id need to adjust the algorithm but we’re off to the seaside …and so im leaving it there!

I got this pretty much there with score system just the column count algorithm isnt quite right but ive had enough of it now and so moving on to something else.

@kotiks i know that you’re good with arrays and im sure you’d be able to do this the using and referring to array.array.structure like you were doing. I used array.structure and so you set the width at the start and add the width to get the cell below but this might be a headache if you’re not used to it.
There are many ways to do this and im not claiming that this is the best. It’s just the way i would do it. Im not going to show all the events i used here as there are lots of them and also there are match3 templates for sale.
the hard bits I found were when you want to check for 3 but also more than 3 (i still havent got this right on the columns) and also the check,delete,fall,repeat cycle was hard. for this i used a loop that’s a bit like a while loop where if one gets deleted process is set to true.

I actually started using arrays and structures after creating a copy of your water mechanics example. Before that, I hadn’t used arrays and structures (if we don’t count very simple functions in programming languages like C++ and C#)

I haven’t touched code since 1986 and i don’t remember using arrays much back then but I love them now. I need to play candy crush or bejewelled again as i cant actually remember how the scoring works. I used to be totally addicted to bejewelled blitz until one day I got a phenomenal score (well to me it was) and there was no fanfare, or red carpet, and no waiters with champagne. It just moved swiftly onto the next game and I thought, Right! well, i’ve got no chance of beating that score, like ever, and I’ve never played it since. Went out on a high i guess.

Ive just sorted that bug on the columns and made it 10 columns of fun!
match3c