How do I spawn enemies faster?

Get help using Construct 2

Post » Mon Jul 07, 2014 6:18 pm

Hey Devs,

I am having troubles increasing the spawn rate of my game.

What I need to do is increase the spawn rate when score reaches 5. Not only does the spawn rate need to increase when the score is 5 but it needs to continuously increase every 5 score.

I have attached an image with my current setup. Any ideas? Thanks! :)
Capture.PNG
You do not have the required permissions to view the files attached to this post.
B
15
S
3
G
1
Posts: 7
Reputation: 1,547

Post » Mon Jul 07, 2014 7:18 pm

Here's how I would do it. Seems to work. Attached is the image for the setup.

Basically the setup is this. Create a variable to hold the SpawnRate. This is the rate your enemies will generate and is based on your needs. 100 per minute or whatever. Whenever your score changes (event #3 in the image) you set a variable named SpawnRateModifier to your Score % 5 (using the modulus operator). This will return 0 if your score is divisible by 5 (so 5, 10, 15, 20, etc.). You also set a value called CheckSpawnModifier to 1 (more on this below).

Then every tick (event #2 in the image) check two conditions: Is SpawnRateModifier == 0 (in other words, is the score divisible by 5) *and* is CheckSpawnModifier == 1. If it is then you do two actions. First, change CheckSpawnModifier to 0. We do this because we're doing this check every tick. If we didn't set this value and check it on every tick, the second action would keep firing the entire time until the score changed. Then for the second action we add 10 to the SpawnRate.

So running this, after a few seconds when the score hits 5, the spawn rate is increased to 110 and stays there until the score reaches 10 at which point the SpawnRate is 120.

Obviously you won't be changing the score every 2 seconds like I did in the demo so it's best to have a function that you call to modify the score and setup these variables at the same time. You can also create variables for SpawnIncrease (instead of a hard coded value) and add that to the SpawnRate.

Hope that helps.

Enjoy!
You do not have the required permissions to view the files attached to this post.
Last edited by bsimser on Mon Jul 07, 2014 7:29 pm, edited 1 time in total.
B
17
S
5
G
2
Posts: 39
Reputation: 1,846

Post » Mon Jul 07, 2014 7:24 pm

create 2 more global variables named stage, counter as numbers

Event:
on collision with Ball

Action:
Add 1 to Score
Add 1 to Counter

Event:
Counter greater or equal 5

Action:
set Counter =0
Add 1 to Stage
B
19
S
6
G
3
Posts: 197
Reputation: 4,154

Post » Mon Jul 07, 2014 8:23 pm

Make a var (something like difficulty) and set 1.
then, create a repeat loop in the same event of the spawn and set the 'count' to the difficulty variable.
you just have to increase the variable every time you want more enemies.
I think this will work.
B
20
S
4
Posts: 387
Reputation: 2,274

Post » Mon Jul 07, 2014 11:13 pm

bsimser wrote:Here's how I would do it. Seems to work. Attached is the image for the setup.

Basically the setup is this. Create a variable to hold the SpawnRate. This is the rate your enemies will generate and is based on your needs. 100 per minute or whatever. Whenever your score changes (event #3 in the image) you set a variable named SpawnRateModifier to your Score % 5 (using the modulus operator). This will return 0 if your score is divisible by 5 (so 5, 10, 15, 20, etc.). You also set a value called CheckSpawnModifier to 1 (more on this below).

Then every tick (event #2 in the image) check two conditions: Is SpawnRateModifier == 0 (in other words, is the score divisible by 5) *and* is CheckSpawnModifier == 1. If it is then you do two actions. First, change CheckSpawnModifier to 0. We do this because we're doing this check every tick. If we didn't set this value and check it on every tick, the second action would keep firing the entire time until the score changed. Then for the second action we add 10 to the SpawnRate.

So running this, after a few seconds when the score hits 5, the spawn rate is increased to 110 and stays there until the score reaches 10 at which point the SpawnRate is 120.

Obviously you won't be changing the score every 2 seconds like I did in the demo so it's best to have a function that you call to modify the score and setup these variables at the same time. You can also create variables for SpawnIncrease (instead of a hard coded value) and add that to the SpawnRate.

Hope that helps.

Enjoy!


Very good code!

That works well but I still need the system event timer to go from 3.5 down to 3.4, 3.3, 3.2...etc every 5 score.
any ideas?

I will attach the .capx file
You do not have the required permissions to view the files attached to this post.
B
15
S
3
G
1
Posts: 7
Reputation: 1,547


Return to How do I....?

Who is online

Users browsing this forum: TRMG, Yahoo [Bot] and 11 guests