Need help creating a "random" output?
in
Programming Questions
•
5 months ago
I am currently writing a motion detection code that "pops" bubbles when they come into contact with a person.
I'm trying to make this code more interesting by having the bubbles become multiple different objects once they reappear off screen (once a bubble is "popped", it's x and y coordinates are randomly moved to allow for a continuous game). I was wondering if there was an easy way to have the bubbles become different shapes randomly?
This is what I've come up with, but I'm receiving a "cannot convert from int to Boolean" error.
Thanks!
I'm trying to make this code more interesting by having the bubbles become multiple different objects once they reappear off screen (once a bubble is "popped", it's x and y coordinates are randomly moved to allow for a continuous game). I was wondering if there was an easy way to have the bubbles become different shapes randomly?
This is what I've come up with, but I'm receiving a "cannot convert from int to Boolean" error.
- void changeShape() {
int shape = int(random(1, 6));
if (shape = 1) {
rect(x, y, radius*2, radius*2);
}
if (shape = 2) {
triangle(x+30, y+75, x+58, y+20, x+86, y+75);
}
if (shape = 3) {
ellipse(x, y, radius*2, radius*2);
}
if (shape = 4) {
fill(random(255), 0, 0, 128);
rect(x, y, radius*2, radius*2);
}
if (shape = 5) {
fill(0, random(255), 0, 128);
triangle(x+30, y+75, x+58, y+20, x+86, y+75);
}
if (shape = 6) {
fill(0, 0, random(255), 128);
ellipse(x, y, radius*2, radius*2);
}
}
Thanks!
1