Collapse game experiment / help

Post your own tutorials, guides and demos.

Post » Thu Mar 12, 2009 9:37 pm

I am trying to figure out how to do a collapse game.

At the moment when I click a block i clear that single block.

But clearing should only happen if the picked/clicked block is connected to at least two other blocks in the same colour. How can I test that?

And if its going to destroyed all the connected blocks in the same color should also be destroyed. How would you guys do that?

Here is my innitial setup
[attachment=0:31xlh7lo]collapse.cap[/attachment:31xlh7lo]

please do some happy hacking :-)
B
4
G
3
Posts: 46
Reputation: 992

Post » Fri Mar 13, 2009 1:34 am

You would need to put the blocks in an array, then use floodfill or something... although I'm sure floodfill uses recursion, and I'd imagine Construct can handle that since a function seems to be able to call itself (just checked).

See here for some methods of flood fill..

http://en.wikipedia.org/wiki/Flood_fill

If you know flash, here's a flash implementation with source that you could try to convert -

http://www.emanueleferonato.com/2008/06 ... mentation/

Maybe you'll get some ideas from those.. maybe someone else will..
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Mar 13, 2009 7:51 am

Before posting this one I did a funny flood fill experiment.

The idea was to create a detector object that is shaped like a " + " and that is slightly bigger than the bricks... the idea of this is to trigger collisions in the directions n, s, e, w

If the detector objects detects a collision it replaces the colliding brick with a detector. This gennerates a flood fill and a nice effect... but this approach will take several frames for the flood fill to be complete. But I really like that way of generating the flood fill and in general the idea of adding "detectors" dynamicly to the stage.
B
4
G
3
Posts: 46
Reputation: 992

Post » Fri Mar 13, 2009 2:02 pm

Yeah it's one way around the problem but to do that every frame for so many blocks, there's no surprise the framerate is low. You'll be much faster using an array and using the floodfill method there.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Mar 13, 2009 7:20 pm

I made one with "+" object and it works pretty well but you have to limit things and disable selecting when blocks are falling.
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Fri Mar 13, 2009 7:28 pm

Well... I dont have any framerate problems. It just takes several frames to compute.

And for the idea of using recursion. The function object fails to do any propper recursion.

I tried to implement a simple recursive calculation of the n'th factorial. n * (n-1) * ... * 1
[attachment=0:39icf8w2]nfac.cap[/attachment:39icf8w2]

it fails... :-(

Any ideas on how to fix this?
B
4
G
3
Posts: 46
Reputation: 992

Post » Fri Mar 13, 2009 7:50 pm

Doppel: yours works for the first go, then it seems a bit random after that.

xombul: You'd have to ask the devs if function object can handle recursion. btw.. if your method worked and there was no noticable slowdown, then go for it :)

Would be interested in getting this sorted 'cause it would be a useful thing to have in the future. I just don't have the time to experiment a lot atm or I would try a few things myself.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Mar 13, 2009 8:35 pm

[quote="Doppel":22r4u5fn]I made one with "+" object and it works pretty well but you have to limit things and disable selecting when blocks are falling.[/quote:22r4u5fn]

I have tried this several a few times before... here is my current go at the "clustor detector pattern"
[attachment=0:22r4u5fn]collapse.cap[/attachment:22r4u5fn]

I just wish I could somehow do it instantly instead of delaying stuff a few frames.
B
4
G
3
Posts: 46
Reputation: 992


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests