Puzzle Matching Like Adjacent Objects - Stuck

Get help using Construct 2

Post » Sat Jan 31, 2015 1:59 am

I have been stuck for awhile now and I'm hoping someone can give me some pointers. I'm working on a game that has a puzzle mechanic similar to a match 3 like candy crush or a bubble blaster game. The part that I am stuck on is recognizing the matches.

I have one sprite in my capx which is called "bug", it is the game token or candy or bubble if that helps for context. In the attached capx example there are 3 bug types each with an idle, hit, panic, destroy, and fall animation all part of the single object. I used an instance variable to identify which bugs are which of the 3 types and it matches with the first part of each animation name. For example type = bee, so beeIdle, beeHit, etc for animation names.

match_test.capx


How the game should work:

Player touches bug> bug animation changes
Player can stay in touch and move from one bug to the next without taking finger off the game and choose a different bug
All bugs that are the same type touching the currently touched bug (4 direction) also change animation and are matched so on touch release all those bugs and the one being touched would change to the destroy animation and then be destroyed

There is no minimum match, so if the player is touching a bug and there are no touching matches then only that bug would be destroyed. If there was only one touching match then the 2 bugs would be destroyed. So it really isn't a match 3 but it is similar. There is no swapping of bugs or drawing a line to match bugs. Just touch bug and all matched bugs touching that bug will be destroyed on touch release.

I've tried using an array and some recursive type solutions, and I looked at a few plugins and templates. I did not include any of my failed attempts at matching in the example capx since I'm embarrassed none of them seemed to work at all. I have searched the forum and read all that I could find on the subject. It does make me want to learn finite state machines more. Thanks in advance for any support.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Sat Jan 31, 2015 5:40 pm

What do you think of this solution?
The basic idea is, you spawn a + shaped image overtop of the tapped bug.
Outside of the Is In Touch block,
For any bug overlapped by the +shaped image, if it's the right variety of bug (and not matched and checked,) you spawn another plus. (and set that bug to matched and checked)
There were a few other adjustments I needed to make- changing the collision polygon of the bugs so you have to be not touching a bug briefly before you're touching another bug, but...
I think this works how you want it!
You do not have the required permissions to view the files attached to this post.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Sat Jan 31, 2015 7:32 pm

@unnatural20 that is a great solution!!! It cascades beautifully and is exactly what I needed. I had tried something similar where I had 4 small sprites spawn out in a "+" pattern but it didn't work and they were individual and not connected. I don't know why I didn't think of making an actual + shaped sprite. I think your idea of making it trigger only once while true also makes a difference compared to what I had tried and I have some ideas to clean up the reasons why the player can sometimes end up picking more than one bug type as a match. THANK YOU!!!!

I realized that the biggest challenge in the ways I had been trying to use arrays is that you can't easily get the x,y,z of a value in an array. You can kind of get it if you check the entire array and use loopindex but not check it starting from a specific x,y,z.
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Sat Jan 31, 2015 7:53 pm

There are a few ways of looking at just a subset of the array. For example, the first time you check for adjacents, you're only looking at the eight squares around the first object. You check for adjacents in just that subset of the array, then store all matches in a separate (list)array of matched array locations.
From that list, you can generate a new rectangle to search for adjacents in- one less than your lowest X to one more than your highest X, and one less than lowest Y to one more than highest Y.

I considered putting together the approach? but I think the + image method resulted in less changes to your game as it was currently designed- and if you're going to implement new bugs dropping in from above, this will work more easily than having to modify an array's entries for gravity.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Sat Jan 31, 2015 10:02 pm

This remind me to the topic I posted below
viewtopic.php?f=148&t=90043

I use a "+" sensor too but with adjusment to the collision polygon.
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226


Return to How do I....?

Who is online

Users browsing this forum: evillair, gamecorpstudio, jorgmaquoi and 14 guests