Problems with Switching Between Random Enemy Spawns
So I had a system in place that spawns a random enemy and drops it from the top of the screen.
I did this by setting the spawning actor's alpha to 1, when this happens it picks a random number, switches the alpha to 0 then goes through a list of enemies and then spawns the enemy the random number matches up to. Finally a timer is set that after x amount of seconds it will set the alpha to 1 again.
The problem I ran into is that I have 2 types of enemies white and black and since it's random I would have too many of one or too many of the other spawn in a row.
What I'm trying to do is that if 3 enemies of the same type spawn in a row I change the next spawn so it has to be the opposite enemy type.
I'm trying 2 ways both of which failed:
The first is that I have a set of counters, the counters are added to for everything spawned and if they hit a certain point it will change the set of random numbers the enemy picker is allowed to pull from.
What happens with this is that it'll spawn 2 things at the same time instead of just one. I've posted images below of how I've done it they're in order as you scroll down the game salad list:
http://i.imgur.com/ho1O2.jpg
The second way I have a counter which switches between 3 spawning states 0 = normal 1= black 2 = white
The problem with this one is that it will swap to say just white and then never swap back to normal and stop spawning entirely. Here is the code:
http://i.imgur.com/9fn6m.jpg
Can anyone help? I've been at it for 2 days and I can't think of anything to fix this or if I need another solution entirely. Thanks!
I did this by setting the spawning actor's alpha to 1, when this happens it picks a random number, switches the alpha to 0 then goes through a list of enemies and then spawns the enemy the random number matches up to. Finally a timer is set that after x amount of seconds it will set the alpha to 1 again.
The problem I ran into is that I have 2 types of enemies white and black and since it's random I would have too many of one or too many of the other spawn in a row.
What I'm trying to do is that if 3 enemies of the same type spawn in a row I change the next spawn so it has to be the opposite enemy type.
I'm trying 2 ways both of which failed:
The first is that I have a set of counters, the counters are added to for everything spawned and if they hit a certain point it will change the set of random numbers the enemy picker is allowed to pull from.
What happens with this is that it'll spawn 2 things at the same time instead of just one. I've posted images below of how I've done it they're in order as you scroll down the game salad list:
http://i.imgur.com/ho1O2.jpg
The second way I have a counter which switches between 3 spawning states 0 = normal 1= black 2 = white
The problem with this one is that it will swap to say just white and then never swap back to normal and stop spawning entirely. Here is the code:
http://i.imgur.com/9fn6m.jpg
Can anyone help? I've been at it for 2 days and I can't think of anything to fix this or if I need another solution entirely. Thanks!
Answers
Once that was done I set rules above it that would say if counterA is = 3 make the min and max these numbers and did the same for counterB. For the normal I just made a rule that if they were both less than 3 change the numbers.
So after that I just added new options to pick between that were all color A and all color B.
The problem before was I had it picking 3 different numbers at the same time this will only pick one.