playMaker

Author Topic: Check for a Match Help  (Read 93 times)

morningstar128

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Check for a Match Help
« on: February 26, 2021, 08:37:40 PM »
Hello,

This is the first time I have ever posted anything on a forum. I have been tinkering around with Playmaker in Unity for a few years and really love it. This forum has helped me the entire way so thank you to everyone on here, this is a fantastic community and you are all awesome.

Now my question, I have been working on a game idea that involves random colored blocks dropping from the top of the screen and falling to the bottom. They can be moved as they fall and colors can be changed while falling. My issue is that I am struggling with how to check for matches when a block lands. I have messed with arrays but not sure how to set them up in an efficient way. I have messed with each block running their own check based on what's around them but it got a bit messy and confusing. I am just looking for a direction to go in for this issue. I feel like I am getting pulled in 20 directions with this issue but really just need a solid simple direct way to put this together.

Currently, I have a bool array for each column with 20 columns. When a block spawns it checks the column it is in so it knows when it will stop. So a block spawns in column 10 and looks to see that level 19 is free so it flips the bool and heads to that spot. if it gets moved left or right it will then check that column and reserve a new spot, while flipping the bool from the previous column. If that is not the right way to do it also please let me know. 

Thanks in advance and thank you all for the last few years of help!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5946
    • View Profile
    • jinxtergames
Re: Check for a Match Help
« Reply #1 on: February 27, 2021, 03:19:51 PM »
Hi.
I made a Tetris game a few years ago :
http://www.jinxtergames.com/web-games/

There i used array maker and several arrays (1 per vertical line)
the reference names of the array i set to 0,1,2,3,etc. this way i can use the position to reference the blocks.
so 0,0 would be top left (array 0 index 0) and 0,23 (array 0 index 23)would be bottom left.

When your block landed you can then get its position and then use Array List Get Next/Previous to check what's next to it.
This part can be a bit intense to setup as you probably want all connected blocks with the same color to be removed.

To check the color you could set a fsm on your block called (for example) Data.
there you can set a int vaule for your 'Color' Id or you could use tags.



i would start by checking horizontal and if the same color blocks are there then add it to an array (connected).

then go thru the connected blocks and check in all directions (but only next to the block not the whole line/row) if a same color exists
Check if the block is already in the list and if not then add to the array (connected)

Then when done you can use Array List Count if you need a certain minimum.
Then you can loop thru the array to despawn then or whatever you need to do with it.

morningstar128

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Re: Check for a Match Help
« Reply #2 on: February 28, 2021, 07:15:54 PM »
Thank you so much for the reply. I am going to try that out and let you know how it goes.