Enemy spawning

I want to make my space shooter game harder. I want it to start off having enemy’s thrown at you every 500 ms. At score 10 I want to make it so the enemy’s shoot at you every 100 ms. I appreciate all the help you people give.

Great question!

So right now I’m guessing you have code that looks something like this:

The on game update ever x ms event always runs at the same rate, so there is no way to make the time interval shorter with that block. Instead, I recommend you use the forever block.

The forever block is similar to on game update with one crucial difference: you can use the pause block inside it. If I were to rewrite the above code with forever instead of on game update, it would look like this:

Because pause takes in a number, we can pass in different numbers to pause for different amounts of time. So to change the speed once the score reaches 10 you could use an if-statement like this:

Or if you wanted to smoothly transition between the two numbers, you could use some math like this:

1 Like

Thanks so much. Unfortunately, the student was out ill for some time. He just forwarded what he has thus far. Thank you for any assistance you can lend!

@richard just wondering if you can help me with my reply to your suggestions. Thanks

@BruceSchwa sure thing!

Looking at this code, i think my above suggestion should work for speeding up enemy spawns. I do see another issue here though; they’re using the “enemy1” variable inside of their overlap events instead of the local variables.

When writing an overlap event (or any other event), you almost always want to use the local variables that you drag out of the event like this:


The reason why is that all variables created in the variables category are global. Every time they create a new enemy inside of that on game update event, the global “enemy1” variable is being updated to point to whatever the most recently created enemy is. Destroying it will destroy the most recently created enemy instead of the enemy that is actually overlapping with the player/projectile.

The variables you drag out of events are local, they refer to whatever sprites are actually involved in the event.