Catching Raindrop Game Help

edited November 2014 in Questions about Code

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);
        }
      }
    }
Tagged:

Answers

Sign In or Register to comment.