Matching more than 3 sprites. (Gem matching)

0 favourites
From the Asset Store
Match 3 Game Gem Pixel Art work for any kind of Match Games.
  • I came up with this solution to match 3 red sprites:

    <img src="http://i.imgur.com/Tdtws.png" border="0" />

    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.

  • 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 ;)

  • 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.

  • 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.

  • 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.

  • 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.

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

    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

    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?

    Like this?

    http://dl.dropbox.com/u/5426011/examples11/pick_all_directions.capx

  • 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:

    <img src="http://i.imgur.com/63o3r.png" border="0" />

    The objects in that chain should get all picked in one click because they keep overlapping each other in a chain.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Selecting a chain of objects is basically a flood fill.

    http://dl.dropbox.com/u/5426011/examples11/pick_chain.capx

  • 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.

  • R0J0hound - How would I accomplish your pick in all directions example for an entire row or column? The game I'm working on allows the user to shift a whole row or column at a time and the sprites wrap at the edges of the board, sort of like a 2D rubix cube. I haven't been able to figure out the matching system for it yet though and your pick in all directions example has given me the most guidance of anything I've found thus far, but I haven't been able to figure out how to get it to do exactly what I need it to.

    I'm pretty sure what I need it to do is start checking the first sprite in the row/column that has been moved, check for matches, then move on to the next sprite in the row/column. If the sprite has already been visited, skip it and move on to the next. Do you have any idea how I would go about doing that cuz I've been hacking at it for days now and haven't gotten anywhere.

  • Such great information here... So much to learn yet @

  • Thanks for this R0J0hound. I was looking for an implementation of flood fill done in Construct 2 and found your post with sample capx. This has been most helpful and informative

  • Ah yes I utilize R0J0 example then modified it to fit my need. Here it is:

  • Really interesting example. Can use it for a bubble shooter game?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)