diff --git a/raindropGameCode/Catcher_Class.pde b/raindropGameCode/Catcher_Class.pde new file mode 100644 index 0000000..dc39ba7 --- /dev/null +++ b/raindropGameCode/Catcher_Class.pde @@ -0,0 +1,18 @@ +class Catcher { //declare variables + PVector loc; //vector location + PImage img; //image name + int diam = 75; //image diameter + + + Catcher() { //set values for variables + loc = new PVector(); + loc.set(mouseX, mouseY); //location is set where the mouse travels + img = loadImage("umbrella.png"); //load image of the umbrella + } + + void display() { + fill(0, 50, 200); //fill color + //ellipse(mouseX, mouseY, diam, diam); + image(img, mouseX, mouseY, diam, diam); //image moves where the mouse is + } +} \ No newline at end of file diff --git a/raindropGameCode/Raindrop_Class.pde b/raindropGameCode/Raindrop_Class.pde new file mode 100644 index 0000000..c8c9001 --- /dev/null +++ b/raindropGameCode/Raindrop_Class.pde @@ -0,0 +1,52 @@ +class Raindrop { //declare variables + PVector loc; + PVector vel, acc; + int diam; + float locx; + float locy; + float t; + int num; + PImage img; + + Raindrop(float locx, float locy) { //set values for variables + t = random(200, 255); + vel = new PVector(0, random(1, 3)); + acc = new PVector(0, random(.2)); + loc = new PVector(locx, locy); + diam = 20; + img = loadImage("hail.png"); + } + + void display() { + fill(255, 255, 255, t); //fill display screen + noStroke(); + + image(img, loc.x - 50, loc.y -50, diam, diam); //image of "hail" movement downward + + //ellipse(loc.x, loc.y, diam, diam); + } + + void fall() { //coding for the hail to fall + loc.y += vel.y; + vel.add(acc); //adding velocity to hail going down + } + + void reset() { //reset hail after it hits 0 + loc.y = 0; + vel.y = 0; + } + + void num() { + } + + boolean isInContactWith(PVector c) { + boolean p; + float d = dist(loc.x, loc.y, mouseX, mouseY); + if (d-diam/2 >50) { + p = false; + } else { + p = true; + } + return p; //returns hail back on top once it is in contact with umbrella + } +} \ No newline at end of file diff --git a/raindropGameCode/data/Rain background.png b/raindropGameCode/data/Rain background.png new file mode 100644 index 0000000..d6fe4ee Binary files /dev/null and b/raindropGameCode/data/Rain background.png differ diff --git a/raindropGameCode/data/hail.png b/raindropGameCode/data/hail.png new file mode 100644 index 0000000..a98966d Binary files /dev/null and b/raindropGameCode/data/hail.png differ diff --git a/raindropGameCode/data/umbrella.png b/raindropGameCode/data/umbrella.png new file mode 100644 index 0000000..70baa33 Binary files /dev/null and b/raindropGameCode/data/umbrella.png differ diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..61430a2 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,57 @@ PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r +int count = 20; +int caught = 0; +//Raindrop [] x = new Raindrop[count]; +ArrayList drops = new ArrayList(); //arraylist + +Catcher c; //catcher class // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object // You can start out by just using the single Raindrop as you test -void setup() { +void setup() { //set values for variables + c = new Catcher(); size(1200, 800); - mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} - r = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions + mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} + drops.add(new Raindrop(random(width), 0)); + //for (int i = 0; i < count; i++) { + // x[i] = new Raindrop(random(width), random(0)) ; + //} } + + void draw() { - mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - background(0, 200, 255); - r.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - r.display(); //display the raindrop - if (r.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - r.reset(); //if it is, reset the raindrop + + if ( drops.size() <2000) { + drops.add(new Raindrop(random(width), 0)); //adds raindrops at a random location on the x axis which is the top of the screen } - if (r.loc.y > height + r.diam/2) { //check to see if the raindrop goes below the bottom of the screen - r.reset(); //if it does, reset the raindrop + + mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + background(0, 200, 255); //set background + textSize(30); //set text size + c.display(); // //display catcher + text(caught,width/2,height/2); //display score at the center of the screen + + for (int i = drops.size()-1; i >= 0; i--) { //raindrop coding + Raindrop x = drops.get(i); + x.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + x.display(); //display the raindrop + if (x.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + x.reset(); //if it is, reset the raindrop + caught++; + println(caught); + } + if (x.loc.y > height + x.diam/2) { //check to see if the raindrop goes below the bottom of the screen + x.reset(); //if it does, reset the raindrop + } + if (x.loc.x> mouseX) { + x.loc.x +=3; + } + if (x.loc.x< mouseX) { + x.loc.x -=3; + } } -} +} \ No newline at end of file