Hi guys. A few people here helped me generate a rain effect and now I'm almost finished making it into a kind of game but there's one thing I can't figure out.
Rain r1;
DraggableObject draggable;
int numDrops = 10;
Rain[] drops = new Rain[numDrops]; // Declare and create the array
int numLadies = 0;
Poshlady[] lady = new Poshlady[3000];
void setup() {
size(600,600);
background(255);
smooth();
noStroke();
//Loop through array to create each object
for (int i = 0; i < drops.length; i++) {
drops[i] = new Rain(); // Create each object
r1 = new Rain();
draggable = new DraggableObject(width/2, height/2);
}
lady[0] = new Poshlady();
}
void draw(){
fill(255,80);
rect(0,0,600,600);
//Loop through array to use objects.
for (int i = 0; i < drops.length; i++) {
drops[i].fall();
float distance = dist(drops[i].r, drops[i].y, draggable.x, draggable.y);
if(distance < drops[i].radius + draggable.radius) {
drops[i].r = random(600);
drops[i].y = random(-200);
}
}
draggable.draw();
if (numLadies == lady.length - 1) exit();
if (random(1000)>997) {
lady[++numLadies] = new Poshlady();
}
for (int i = 0; i < numLadies; i++) {
lady[i].walk();
float distance2 = dist(lady[i].x, lady[i].y, drops[i].r, drops[i].y);
if(distance2 < lady[i].radius + drops[i].radius) {
exit(); }
}
}
void mousePressed() {
draggable.mousePressed();
}
void mouseDragged() {
draggable.mouseDragged();
}
void mouseReleased() {
draggable.mouseReleased();
}
class Rain {
float r = random(600);
float y = random(-height);
float radius = 5;
void fall() {
y = y + 7;
fill(0,10,200,180);
ellipse(r, y, 2*radius, 2*radius);
if(y>height){
r = random(600);
y = random(-200);
}
}
}
class DraggableObject {
float x, y;
float radius;
boolean drag;
float dragX, dragY;
DraggableObject(float _x, float _y) {
x = _x;
y = _y;
radius = 30;
drag = false;
dragX = 0;
dragY = 0;
}
boolean inside(float ix, float iy) {
return (dist(x, y, ix, iy) < radius);
}
void draw() {
ellipseMode(CENTER);
fill(200,0,0);
ellipse(x, y, 2*radius, 2*radius);
}
void mousePressed() {
drag = inside(mouseX, mouseY);
if (drag) {
dragX = mouseX - x;
dragY = mouseY - y;
}
}
void mouseDragged() {
if (drag) {
x = mouseX - dragX;
y = mouseY - dragY;
}
}
void mouseReleased() {
drag = false;
}
}
class Poshlady {
float x = random(width,width+width/3);
float y = height-height/5;
float radius = 40;
float r = random(3);
void walk() {
x = x - r;
fill(0,10,200,180);
ellipseMode(CENTER);
ellipse(x, y, 2*radius, 2*radius);
}
}
Eventually the red circle will be an umbrella and the large blue ones will be 'posh ladies' you have to protect from the rain (random I know). The problem is for some reason most of the time you can get away with the rain touching the blue circles (it is supposed to exit if that happens for the moment..). Sometimes it woks and other times the rain goes straight through.
Any ideas?