Last night, I worked on a capx from 7:00PM to 3:00 AM and didn't get what I wanted.
I need to create Match3 mechanics for my game.
I began with creating an array (6,6,1) where the values are Int(Random(4)).
Then, for each XY, I create an instance of "Gem" (sprite with 4 animations, each being a color). The color is decided by the Int(Random(4)) value (0=Blue, 1=Yellow, 2=Red, 3=Green).
So, I got a 6x6 board of gems.
But I need to know if 3 or more cells of the same color are touching.
So I created an instance var for "gem" that stores the animation name (color), a Global variable called "PreviousColor" and another called "clickCount".
If clickCount = 0, create a "selection" object over the clicked Gem, store the Gem color in the PreviousColor global var, set clickCount to 1.
If clickCount =/= 0, check if PreviousColor = Gemme.Color
The rest of the code is gibberish: newbie attempts to check when same color if both gems are connected, and that doesn't work.
Check out these plugins, courtesy of rexrainbow, they make doing games like that quite effortless: scirra.com/forum/plugin-matcher_topic57512.html
I'm trying to do a game, which uses Match 3 mechanics too. Yesterday I found:
It takes only five events to generate grid with random objects. Shame there isn't part two (and most likely won't appear), because I'm a beginner too.
Now I struggle with proper swaping of them.
EDIT: Thanks, vee41, for these links!
Develop games in your browser. Powerful, performant & highly capable.
Meh. My previous message hasn't been sent and was deleted on refresh...
vee41: I'll try that, but I would prefer to understand what I'm doing. Thanks, though, it could be interesting.
Bluehardt: been there. I think the trick of the "string to generate randomness" is a little bit too much, though. Did the same thing with the Array value at (X,Y) is (Int(random(4)) and the random integer determines the color.
I wonder if adding a Z-axis to my array could help if I do this:
the value at (X,Y,2) is 0 on start of layout.
Then, for each element of the array, I compare the value with the previous, the next, the one above and the one below (so I compare (X,Y) with (X-1,Y), (X+1,Y), (X,Y-1) and (X,Y+1). If the value at (X,Y) and any of those is the same, I add 1 on (X,Y,2).
That way, I could trigger events if Z>=3...
This thread would help you