Recursion in Construct 2

Get help using Construct 2

Post » Wed Oct 17, 2012 7:05 pm

I am making a EggShooter like BubbleShooter.
If the player hit a egg, the program have to collect all eggs around with the same color.
after using this function all the eggs with property net = 1 can be removed.

In code I do it this way, and I wonder how to do this in Construct 2

function BuildNetByColor(xx, yy, color)
{
    For Each(egg in Eggs)
    {
        if (egg.net == 0)
        {
            if (egg.visible)
            {
               if (egg.AnimationFrame == color)
               {
                    if (egg.distance_to_point(xx,yy) < 40)            
                    {
                        egg.net = 1;
                        BuildNetByColor(x, y, col);//recursion
                    }
               }
            }
        }    
    }
}
B
13
S
4
G
5
Posts: 8
Reputation: 3,795

Post » Wed Oct 17, 2012 8:39 pm

here is the EggShooter so far: EggShooter with Construct 2 http://www.scirra.com/FORUM/smileys/smiley17.gifEgg2012-10-17 20:49:56
B
13
S
4
G
5
Posts: 8
Reputation: 3,795

Post » Wed Oct 17, 2012 9:49 pm

You could use the third party function plugin. You could also implement a stack with the Array object which I've done before for a flood fill algo.

Here are some examples of alternative ways:
Here is an example that uses a stack and goes until the stack is empty.
http://www.scirra.com/forum/in-something-enclosed-or-is-it-just-me_topic53841_post340661.html#340661

This does it in a while loop. It works by visiting each object which in turn pick unpicked objects. It finishes when all the picked have been visited.
http://www.scirra.com/FORUM/matching-more-than-3-sprites-gem-matching_topic51703_post326543.html#326543

EDIT:
It seems to torment the chicken when you shoot eggs.R0J0hound2012-10-17 21:51:15
B
79
S
24
G
54
Posts: 4,738
Reputation: 40,739

Post » Thu Oct 18, 2012 7:38 pm

Thanks a lot

I look on it and try it out...
B
13
S
4
G
5
Posts: 8
Reputation: 3,795

Post » Sun Oct 21, 2012 9:28 pm

@R0J0Hound

Thanks of your help with just 5 events, all the eggs are picked

After 20 years C++ programming, I have to learn the Ashley Language

Let's call it A++

C2 is Amazing, very fun to work with!

EggShooter
Egg2012-10-21 21:39:38
B
13
S
4
G
5
Posts: 8
Reputation: 3,795

Post » Mon Oct 22, 2012 12:42 am

You can't win. :( Fun game anyways. Great art.
B
37
S
9
G
7
Posts: 143
Reputation: 6,017

Post » Mon Oct 22, 2012 9:10 pm

@baspenguin this is just the begin...
B
13
S
4
G
5
Posts: 8
Reputation: 3,795

Post » Fri Jan 11, 2013 3:15 pm

@Egg
I've your problem, can you help me?
B
17
S
5
G
3
Posts: 76
Reputation: 2,948


Return to How do I....?

Who is online

Users browsing this forum: Braus, Google [Bot], zeneizel and 14 guests