We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I need the raindrops to disappear once the mouse is rolled over them and the score to increase every time the raindrop is rolled over.
Main tab:
Raindrop[] theRaindrops;
int numberOfRaindrops = 30;
Bucket bucket;
int score = 0;
void setup() {
size(500, 500);
background(225);
theRaindrops = new Raindrop[numberOfRaindrops];
for (int i=0; i<numberOfRaindrops; i ++) {
theRaindrops[i] = new Raindrop(random(0, 500), 0, random(-6, 6));
}
bucket = new Bucket(mouseX, mouseY);
}
void draw() {
background(255);
fill(0);
textSize(30);
text("Your Score is: " + score, 10, 30);
for (int i =0; i<numberOfRaindrops; i++) {
theRaindrops[i].display();
theRaindrops[i].rain();
}
bucket.display();
bucket.setLocation(mouseX,mouseY);
}
//not working
//void mousePressed() {
// for (int i=0; i<numberOfRaindrops; i++) {
// if (theRaindrops[i].hasBeenClicked(mouseX-15, mouseY-25)) {
// if (theRaindrops[i].haveYouBeenClicked ()) {
// score++;
// }
// theRaindrops[i].haveYouBeenClicked();
// }
// }
//}
Bucket tab:
class Bucket {
float myX;
float myY;
Bucket(float mouseX, float mouseY) {
myX = mouseX;
myY = mouseY;
}
void display() {
fill(0);
rect(mouseX-15, mouseY-25, 30, 50);
}
void setLocation(float tempX,float tempY){
myX = tempX;
myY = tempY;
}
boolean intersect(Raindrop d){
if((myX<30) || (myY<30)){
return true;
}
else{
return false;
}
}
}
Raindrop tab:
class Raindrop {
float myX;
float myY;
float myYVel;
boolean no;
Raindrop(float x, float y, float yVel) {
myX = x;
myY = y;
myYVel = yVel;
}
boolean haveYouBeenClicked() {
return no;
}
float getX() {
return myX;
}
float getY() {
return myY;
}
void display() {
fill(0, 0, 255);
ellipse(myX, myY, 20, 20);
}
boolean hasCollided(Raindrop otherRaindrop) {
if (otherRaindrop.getX() +50 > myX) {
if (otherRaindrop.getX() < myX + 50) {
if (otherRaindrop.getY() +30 > myY) {
if (otherRaindrop.getY() < myY +30) {
return true;
}
}
}
}
return false;
}
boolean hasBeenClicked(float mouseX, float mouseY) {
if ((myX < mouseX) && (mouseX < myX + 50)) {
if ((myY < mouseY) && (mouseY < myY + 30)) {
return true;
//myY=0;
}
}
return false;
}
void rain() {
myY = myY + myYVel;
if (myY>500) {
myY=50;
myX = random(0, 500);
}
}
}
Answers
Please, re-edit your code! Highlight it and hit CTRL+K in order to format it for the forum! L-)
BtW, here's an online rainy cloud: http://studio.processingtogether.com/sp/pad/export/ro.9l84$2z--gWui/latest
you need to call hasBeenClicked(mouseX,mouseY)
if true you can mark the raindrop as existsRaindrop = false;
or better set it myY to -222
then it reappears later
(and score++; of course)
do you want it so that the mouse always kills drops or only when the mouse is clicked?
;-)
Online bucket rain game: http://studio.processingtogether.com/sp/pad/export/ro.9mzpXAdqbigsO/latest
Online catch balloon game: http://studio.processingtogether.com/sp/pad/export/ro.9V7R1wu55fOiN/latest