Help getting contiguous multipliers on a grid.

0 favourites
  • 6 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • so I have a grid of squares. The red squares are player's pieces and the grey squares add a multiple to the player's red pieces.

    so if a red piece is adjacent to a grey piece the red piece gets 2X multi. but if there are grey pieces contiguous with with that grey piece, you would do 2X*2X, then another 2X*2X*2X.

    Currently in the game I am doing adjacency with another overlapping sprite then a For Each, but I'm having trouble with the contiguous part. Seems like I would just get into a recursive nightmare.

    Probably need to do two passes where I would set the grey piece's multiplier first. but still having trouble wrapping my head around this one.

    Any thoughts?

  • You can do a flood fill on the grey blocks. Start at a random block, then flood to the connected. Repeat until you have each group of blocks marked. Then It's mostly the matter of picking that group, and using picked count for the factor.

    There may be other ways to do it too.

    dropbox.com/s/l8p8sngj1wu5etx/flood_fill_blocks.capx

  • thanks R0J0hound that's exactly what I was looking for, flood fill. I haven't had to ever do one of those!

    you are using "is overlapping" but as far as I can tell they are right up against each other and not overlapping, not sure how that works.

  • not loving the triple nested loop! ouch. but this is where I thought I had to go, I just couldn't see it. Thanks again!

  • The blocks are in contact with each other so they count as overlapping.

    The triple loop isn’t bad since the amount of iteration get lower rather fast.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound oh I just meant to understand. Anything beyond a couple loops makes my head hurt! but I could follow it.

    The blocks are in contact with each other so they count as overlapping.

    good to know!

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