diff --git a/raindropGameCode/catcher.pde b/raindropGameCode/catcher.pde new file mode 100644 index 0000000..d0e3304 --- /dev/null +++ b/raindropGameCode/catcher.pde @@ -0,0 +1,20 @@ +class Catcher{ + PVector loc; + int diam; + + Catcher(int tdiam){ + loc = new PVector(); + diam = tdiam; + } + + void display(){ +fill(0); +ellipse(loc.x,loc.y,diam,diam); + } + + void update(){ + loc.set(mouseX,mouseY); + } + +} + \ No newline at end of file diff --git a/raindropGameCode/raindrop.pde b/raindropGameCode/raindrop.pde new file mode 100644 index 0000000..f6efc62 --- /dev/null +++ b/raindropGameCode/raindrop.pde @@ -0,0 +1,33 @@ +class Raindrop {// declaring all fields contained within Raindrop Class + PVector loc, vel, acc; //declare variables and PVectors and intergers + int diam; + Raindrop(float x, float y) { + diam = 30; + loc= new PVector(x, y); + vel = new PVector(random(-3, 3), random(-3, 3)); + acc = new PVector(0, .01); + } + void display() { + fill(253); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); + } + void fall() { + loc.y=loc.y + vel.y; // add velocity to create fall + vel.add(acc); //add gravity to the game + } + void reset() { + loc.y=0; + vel.set(0,10); + } + boolean isInContactWith(PVector mouse) { //get rid of the rain + float d = dist(loc.x, loc.y, mouse.x, mouse.y); //determine if the mouse is within the circle/in contact + boolean c; + if ( d < diam/2) { + c = true; + } else { + c =false; + } + return c; + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..fd0ac96 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,6 +1,8 @@ +int count=100; PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r - +ArrayList raindrops = new ArrayList(); +//Raindrop[] r = new Raindrop[count]; //declare a new Raindrop called r +Catcher c; // 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 @@ -8,19 +10,38 @@ Raindrop r; //declare a new Raindrop called r void setup() { 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(); +c = new Catcher(50); +raindrops.add(new Raindrop(mouseX,mouseY)); +//for(int i = 0; i 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 + raindrops.add(new Raindrop(random(width),0)); + c.update(); + c.display(); + for(int i = raindrops.size()-1; i >= 0; i--){ + Raindrop r = raindrops.get(i); + r.display(); + r.fall(); + if(r.isInContactWith(mouse)){ + raindrops.remove(i); + } } -} + //for(int i = 0; i < count; i++){ + //r[i].fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + //r[i].display(); + ////display the raindrop + //if (r[i].isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + // r[i].reset(); //if it is, reset the raindrop + //} + //if (r[i].loc.y > height + r[i].diam/2) { //check to see if the raindrop goes below the bottom of the screen + // r[i].reset(); //if it does, reset the raindrop + //} + //} +} \ No newline at end of file