Random spawn from other spawn

Get help using Construct 2

Post » Tue Nov 06, 2012 12:23 pm

I would like to generate a explosives package randomly each time the player exploded a stone. I thought of creating a spawn from the sprite with the explosion (fire+smoke animation), but would have to be random, ie, the explosives package only appears in some explosions. Someone would have an idea of how to do this?
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Tue Nov 06, 2012 3:19 pm

Ive an idea and and it worked but I don't know if is the better solution:

Rock onDestroyed > System > Set randomNun to random(11)
(sub-event) System > randomNum>=8 > Explosion > Spawn bulletPackage on layer 1(image point 0)
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Tue Nov 06, 2012 3:27 pm

That's a good way to to do it. I would recommend for good clean programming to take out the hardcoded random(11) and random>=8 and change those to variables such as explosionChance and explosionChanceRange.

The put those variables somewhere like a blank sprite off screen where you can store game wide variables or use global variables. Then you always know where to find those values if you want to tweak them in the future.
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Tue Nov 06, 2012 6:44 pm

Thanks for the tips, @justifun. I'm still learning.
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Wed Nov 07, 2012 11:45 am

I created a system but I believe that is not very efficient. What do you think? (notice that I have not changed the variable names, but I'll do it)

System > Every 1 seconds > System > Set randomNum to random(15)

*(sub-event) System randomNum <= 7 > System > Create object rock1 on layer1 at (random(80,640), player.Y+650)

*(sub-event) System randomNum > 7 / System randomNum <=12 > System > Create object rock2 on layer1 at (random(150,550), player.Y+680)

*(sub-event) System randomNum > 12 > System > Create object rock3 on layer1 at (random(300,480), player.Y+710)
B
65
S
13
G
2
Posts: 969
Reputation: 6,732

Post » Thu Nov 08, 2012 7:00 pm

Another doubt:It would be interesting to use a command randomization separately for each object created?(in this case, using system>every sec three times). This way, different objects could have created simultaneously and interchangeably. I would love to hear from you about these two issues. This will help me to learn how to create systems that are more interesting. Thanks.RenatoB2012-11-08 19:02:10
B
65
S
13
G
2
Posts: 969
Reputation: 6,732


Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt and 13 guests