Random number, but not all numbers?
DrGlickert
Member Posts: 1,135
So in my bubble shooter type game I have different color blocks and different colored shots.
So, my thought is that when all "red" blocks are gone that the "red" balls won't generate anymore.
So on my cannon the balls generate a random number before shooting (1-6). Can I make some rule that when all red blocks are gone the random number generator only generates numbers between 1-6 but NOT 2 (red)?
Is this possible? What's the best way to accomplish this?
So, my thought is that when all "red" blocks are gone that the "red" balls won't generate anymore.
So on my cannon the balls generate a random number before shooting (1-6). Can I make some rule that when all red blocks are gone the random number generator only generates numbers between 1-6 but NOT 2 (red)?
Is this possible? What's the best way to accomplish this?
Comments
First, you'll need an attribute that checks whether or not any of a certain color block are gone. You'll probably need one for each color. Check out this vid for more details on how to do that:
Next, you'll need additional rules for your ball spawning. I'm going to assume you have something along the lines of "random (1,6)"; if 1, spawn blue; if 2, spawn red, if 3, spawn yellow, etc.
Now, when red = 0 (ie, all red blocks are gone), have a rule set up in your spawn rule under the red spawn that says "if random = 2 AND red>0, spawn red. If random=2 AND red = 0, change random to 1,6"
Now put that rule for each color, changing the "red" attribute to the correct color for each. Basically this way it'll keep changing random until it comes across a color that hasn't zeroed out yet.
That, at least, is one way to do it - I'm sure there are others that might be better. :-)
If say, you have every second random (1,6) and it generates a color that...
Nevermind... I see you've already covered that :P
We have blue = 1, red = 2, yellow = 3
Random.colour= random(1,3)
When Random.colour = 2 and red > 0 do ...
Nested
When Random.colour = 2 and red < 1
Change Random.colour to 3
This is repeated for all the co ours and the change in the last line also changes number so another colour is chosen. I just thought. A check needs to be added so it doesn't loop continue sly if all the co ours are used up.
Hope this helps