How do I spawn specific numb of enemies randomly periodicall

Get help using Construct 2

Post » Sat Aug 29, 2015 2:49 am

So, what I want to do, is create a bunch of spawn points off map, and set for enemies to spawn randomly at this spawn points periodically. I also want to have a specific total number of spawns.

Example.
I create 30 spawn points.
I want 20 enemies to spawn, between these spawn points
I want the enemies to spawn roughly within a 2 minute time frame
So I want each spawn to lower a specific value, when that value reaches 0, the random spawning is turned off on all points.

My goal is this helps future level creation easy, because all of the code is identical, and all I need to change is how many total enemies I want to spawn, so I just adjust that variable up to increase difficulty.

A concern I have after doing this is, with a random function, will i sometimes have instances when I have a bulk of the spawns go off all at the same time? If so, is there a way to manage spawn frequency between all points to keep them within some sort of threshold. Like no more than x amount of units will spawn within y amount of seconds of each other... something of that nature.
B
6
S
1
Posts: 47
Reputation: 472

Post » Sat Aug 29, 2015 9:39 am

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Sat Aug 29, 2015 4:12 pm

You could make an array with the locations, then just make an event every 120 seconds with repeat 20 to spawn an object, use array.at with random to select one of your spawn points.
B
6
S
1
Posts: 67
Reputation: 636

Post » Sat Aug 29, 2015 7:20 pm

Ram, that is helping me some, I'll mess around with it some more, but is there a way to add in a spawn limit for number of units spawned?

Martin, I was trying to mess with arrays, also using the tutorial here on scirra's website, but they depict an actualy seeable object, but when I make an array, I do not actually see it. I think the array method, in reading how they work, may actually work great. Seems I can set an array on all 4 sides, and spawn from them at random. so I want to learn more about them.

I will try to learn some by looking up some youtube video's, but I usually learn best by manipulating similar code to what I'm looking for, so may see if I can find some turorial that includes some base code for me to play with and learn off of.
B
6
S
1
Posts: 47
Reputation: 472

Post » Sat Aug 29, 2015 8:38 pm

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Sun Aug 30, 2015 2:24 am

Ok Ram, you def have me in the right direction and I'm almost there. I understand the functions a little more clearly now, but still have a problem translasting it. I tried to bring it over more or less exactly, but without the wave functionality you built in yours, since mine is going to be more of a level system rather than waves. When doing that, It wouldn't wait between spawns, and it is spawning them infinitely.

I got into looking through tutorials of some of the functions, and I wonder would the repeat function be something that would work for me? In my mind, I want to take the system repeat function, tell it to repeat x amount of times, then I want it to spawn object with a random range delay, so I could do random (3, 5) and it would randomly spawn between every 3 to 5 seconds. Then lastly, I want to use your set frame option, to have it randomly choose which one to spawn from.

End result, game randomly selects spawn point every 3-5 seconds, spawns a unit, and repeats that function x amount of times. I'm going to mess with it a little longer before I call it a night.

Edit: So I messed around with it a bit longer, and I came up with something that to me logically should work perfect, but logic isnt winning here. Here is what I have

Condition: Repeat 10 times
Condition: Pick a random instance (spawn sprite selected)
Action: System wait 5*loopindex
Action: (Spawn sprite) spawn (Object sprite)

What I expected was for it to spawn the object 10 times, once every 5 seconds at a random spawn. What I got was it just spawning an infinite amount of objects at every spawn. I also tried your for command that you used, and ended up with the same result. I think I'm close, just missing something small I'm sure.
B
6
S
1
Posts: 47
Reputation: 472

Post » Sun Aug 30, 2015 7:53 am

remember with C2 it constantly loops through the code - it sounds like you just need to add a

"while this "level" is true do..."
"make this "level" no longer true"
Condition: Repeat 10 times
Condition: Pick a random instance (spawn sprite selected)
Action: System wait 5*loopindex
Action: (Spawn sprite) spawn (Object sprite)


so in my case I was using "gvWaveDelayCoundtdown" - this prevents the for/next loop running multiple times ...
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Sun Aug 30, 2015 8:32 am

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Mon Aug 31, 2015 3:58 am

RAM! Thanks sir. That last bit worked perfect. I want to make sure I have a grasp on why, so I can help myself more going forward, because it took me a few tries to add the items myself (I didnt want to just copy your code and change the values, and I'm glad I didnt since I made some mistakes I learned form along the way.

1) The create object line in the beginning, true, to false, makes it so it doesn't infinitely run the routine, and rather just runs 1 instance of it.
2) Making it a sub event, rather than a complete list of separate events also accomplishes that
3) Loopindex makes it so the asteroids actually spawn 1 at a time, up to the value listed, rather than all firing off at the same time, at the value listed

Does that sound about right?

1 last question, doesn't look like I gcan make a global value random(x,y) correct? It always sets value to 0. So if I want to have a little variance in my spawn time, I'll just have to ditch the GV, and put in the random(x,y) code with the loopindex?
B
6
S
1
Posts: 47
Reputation: 472

Post » Mon Aug 31, 2015 7:44 am

" I'm glad I didnt since I made some mistakes I learned form along the way" - best way to learn in my opinion.

1- Yes -but , as always, there are other ways to do this
2 - Not in this case , but it did make it easier to understand :) - if you include the sub-conditions (in the same order) in with the main condition and also move the actions into the same block then it should still work :I've not checked this , please try it and see...
3 - the loopindex is the number of time it steps through the loop so the wait loopindex * X will delay the next action by X seconds, the second time through the loop is will delay the next action by 2*X seconds,etc . But the loop will run through all its repeats straight after each other and then move onto the next condition the waits sort of buffer the next actions ... the wait does not pause the whole program only the actions following it into a delayed list of actions to complete as their time comes up. Make sense ?

last question - you could still use a global variable (gvDelay ?) and set this (in code) to random(x,y) before setting the loop to start. Don't think upon defining a variable you can set it to a random number.

edit - v4

https://www.dropbox.com/s/ryi4heshbjmkf ... .capx?dl=0
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Next

Return to How do I....?

Who is online

Users browsing this forum: justifun and 10 guests