Spawning Different Enemies At Different Rates

So I have my game that has 5 enemies that spawn and move across the screen.

I am trying to find a way to spawn these enemies with a simple set of rules. One enemy spawns consistently while the other enemies spawn less often (each zombie has its own frequency to when it should spawn). Over time this should become slightly faster.

I am trying to figure out the code to spawn them in small spurts based on this logic. NO IDEA where to start. I have experimented with timers but this has become quite cluttered and inefficient. Spawning one set every 2 seconds, then the next every 5 seconds, and so on is just too uniform.

A simple example may be 3 of the consistent enemies spawn right after another, then a small pause, then 4 spawn but one of the 4 is one of the less frequent enemies. This type of behavior would be random and gradually go faster.

Any ideas would be great! Thanks [import]uid: 71971 topic_id: 32264 reply_id: 332264[/import]

Dude I’d totally just have like, a counter for the enterFrame update loop - decrement it each update - when it reaches zero, spawn some enemies. Each time you spawn, reset that counter to be less than what it was before so that the spawns gradually become faster.

You’ve pretty much answered your own question, dude. If you’re spawning enemies randomly, let’s say you’re saying like…oh, I dunno…
[lua]num = math.random(lowerBound, upperBound)
if (num % 5 == 1) then
spawnEnemy()
end[/lua]
You could also like, decrease the bounds by which the random is generated each time you reset that update counter, thus having more chance of enemies being spawned.

There’s plenty you can do man. [import]uid: 144339 topic_id: 32264 reply_id: 128371[/import]

Dude I’d totally just have like, a counter for the enterFrame update loop - decrement it each update - when it reaches zero, spawn some enemies. Each time you spawn, reset that counter to be less than what it was before so that the spawns gradually become faster.

You’ve pretty much answered your own question, dude. If you’re spawning enemies randomly, let’s say you’re saying like…oh, I dunno…
[lua]num = math.random(lowerBound, upperBound)
if (num % 5 == 1) then
spawnEnemy()
end[/lua]
You could also like, decrease the bounds by which the random is generated each time you reset that update counter, thus having more chance of enemies being spawned.

There’s plenty you can do man. [import]uid: 144339 topic_id: 32264 reply_id: 128371[/import]

Thanks for that Lionel! I was searching for something like this, but can you explain what this means?

(num % 5 == 1)

Thats the only part I dont “get”. Thanks! :smiley:

% = modulo
 

Works like this:
5%5 = 0

10%5 = 0

15%5 = 0

6%5 = 1
7%5 = 2

9%5 = 4
11%5 = 1
23%5 = 3

See the pattern? X mod Y = Z (X % Y = Z) where Z is the remainder when you divide X by Y

Random example:
46 % 3 = ?

The closest I can come to 46 without reaching over by only multiplying 3 is 45 (15*3), 46-45 = 1 (the remainder).

Simple but useful in programming

I think i get it…

So, if I had like 44%2, is would equal zero right? Cause the answer would be 22 with no remainder. Am I getting that right? Thanks, my friend. I appreciate it. These forums are the most helpful I have ever been on in over 20 years. Thanks again for explaining things for me.

Thanks for that Lionel! I was searching for something like this, but can you explain what this means?

(num % 5 == 1)

Thats the only part I dont “get”. Thanks! :smiley:

% = modulo
 

Works like this:
5%5 = 0

10%5 = 0

15%5 = 0

6%5 = 1
7%5 = 2

9%5 = 4
11%5 = 1
23%5 = 3

See the pattern? X mod Y = Z (X % Y = Z) where Z is the remainder when you divide X by Y

Random example:
46 % 3 = ?

The closest I can come to 46 without reaching over by only multiplying 3 is 45 (15*3), 46-45 = 1 (the remainder).

Simple but useful in programming

I think i get it…

So, if I had like 44%2, is would equal zero right? Cause the answer would be 22 with no remainder. Am I getting that right? Thanks, my friend. I appreciate it. These forums are the most helpful I have ever been on in over 20 years. Thanks again for explaining things for me.