Matching more than 3 sprites. (Gem matching)

Get help using Construct 2

Post » Wed May 02, 2012 3:14 pm

I came up with this solution to match 3 red sprites:



What this does is get the position of the middle sprite when 3 sprites are right next to each other, and then destroy itself and the sprite to the left and the one to the right.

This works well, the problem is I don't know how to expand it so if there are more matching sprites (more than 3 in a row) they also get destroyed.

All suggestions are welcome.Xavier2012-05-02 15:20:06
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Wed May 02, 2012 6:19 pm

EDIT: The following applies only if you are making a bejewled-type game based off a grid.

You really should be representing your whole grid with an array. All changes you make should be to the array, then you can read to determine block positions.

This way you will have a LOT less trouble, and you won't have to do events as complex as this.

Now there are many things you can do to determine rows, as well as more complex features for your game!

I am not sure of the algorithms for finding a row, however. I would ask @Yann as he seems to be the array master here, having created a 3D maze game based off arrays ;)
sqiddster2012-05-02 18:20:48
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu May 03, 2012 8:50 am

Hello. How do you actually represent the array into a grid in the editor, so every cell represents a value in the array?
I've seen some grid examples in the FAQ but they don't use arrays.
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Thu May 03, 2012 6:16 pm

You can do it without an array.
http://dl.dropbox.com/u/5426011/examples11/pickrow.capx
It looks at each sprite then move the detector left until it isn't overlapping a sprite. Then the detector is moved right and that run of sprites are picked.

Columns of sprites can be picked in a similar manner.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu May 03, 2012 9:45 pm

@R0J0hound... Wouldn't you recommend he use an array anyway considering the type of game?

In terms of representing the grid, just multiply the x and y coordinates in the array by the width and height of the cells and set the object's positions according to this.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri May 04, 2012 10:05 am

Thank you both for the answers.

@R0J0hound I would like to modify that example so it checks on all 8 directions, moving 32 pixels at a time like in the example, would that be possible?

This is for another project, I'll get back to arrays another time.
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Fri May 04, 2012 6:52 pm

[quote]...Wouldn't you recommend he use an array anyway considering the type of game?[/quote]
You can use an array and it would likely be faster, but it uses more events. For me it was just a matter of preference.
http://dl.dropbox.com/u/5426011/examples11/pickrow_array.capx

[quote]I would like to modify that example so it checks on all 8 directions, moving 32 pixels at a time like in the example, would that be possible?[/quote]
Like this?
http://dl.dropbox.com/u/5426011/examples11/pick_all_directions.capx
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sun May 06, 2012 8:14 pm

@R0J0hound
Yes, exactly, many thanks, that was very helpful. It's getting more complicated to understand though with these expressions :P

Do you have any idea if it would be easy to make so that every object that is "picked", also keeps checking in their 8 directions?

For instance:



The objects in that chain should get all picked in one click because they keep overlapping each other in a chain.
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Mon May 07, 2012 1:56 am

Selecting a chain of objects is basically a flood fill.
http://dl.dropbox.com/u/5426011/examples11/pick_chain.capx
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon May 07, 2012 12:45 pm

Thanks again. I've been able to modify it a little so it works on a family of different sprites (colors).
I've also taken a look at the wikipedia's flood fill entry, very interesting read.Xavier2012-05-07 12:46:02
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 5 guests