From 6f35678a76c7b8fdcd069718ac040a7cf31ebde6 Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Mon, 14 Dec 2015 14:49:42 -0500 Subject: [PATCH 1/4] raindrop game --- raindropGameCode/raindrop.pde | 34 +++++++++++++++++++++++++++ raindropGameCode/raindropGameCode.pde | 26 ++++++++++++-------- 2 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 raindropGameCode/raindrop.pde diff --git a/raindropGameCode/raindrop.pde b/raindropGameCode/raindrop.pde new file mode 100644 index 0000000..e59222e --- /dev/null +++ b/raindropGameCode/raindrop.pde @@ -0,0 +1,34 @@ +class Raindrop {// declaring all fields contained within Raindrop Class + PVector loc, vel, acc; + int diam; + Raindrop(float x, float y) { + diam = 30; + loc= new PVector(x, y); + vel = new PVector(random(-5,5),random(-5,5)); + acc = new PVector(0, 0.3); + } + void display() { + fill(253); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); + } + void fall() { + loc.y=loc.y + vel.y; + vel.add(acc); + } + void reset(){ + loc.y = 0; + vel.set(0,10); + } + boolean isInContactWith(PVector mouse) { + float d = dist(loc.x, loc.y, mouse.x, mouse.y); + 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..dc225ff 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,5 +1,6 @@ +int count=100; PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r +Raindrop[] r = new Raindrop[count]; //declare a new Raindrop called r // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object @@ -8,19 +9,24 @@ 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(); +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 + 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 From 47eb3bb9f2a82637b716428a0a7155d848c5fd83 Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Wed, 16 Dec 2015 13:55:32 -0500 Subject: [PATCH 2/4] comments added --- raindropGameCode/raindrop.pde | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/raindropGameCode/raindrop.pde b/raindropGameCode/raindrop.pde index e59222e..f82c881 100644 --- a/raindropGameCode/raindrop.pde +++ b/raindropGameCode/raindrop.pde @@ -1,5 +1,5 @@ class Raindrop {// declaring all fields contained within Raindrop Class - PVector loc, vel, acc; + PVector loc, vel, acc; //declare variables and PVectors and intergers int diam; Raindrop(float x, float y) { diam = 30; @@ -13,15 +13,15 @@ class Raindrop {// declaring all fields contained within Raindrop Class ellipse(loc.x, loc.y, diam, diam); } void fall() { - loc.y=loc.y + vel.y; - vel.add(acc); + loc.y=loc.y + vel.y; // add velocity to create fall + vel.add(acc); //add gravity to the game } void reset(){ - loc.y = 0; + loc.y = 0; //reset the drops vel.set(0,10); } - boolean isInContactWith(PVector mouse) { - float d = dist(loc.x, loc.y, mouse.x, mouse.y); + 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; From aca642f50f5f7996ae4acdd841b9e7a9b109e9e7 Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Wed, 16 Dec 2015 14:50:29 -0500 Subject: [PATCH 3/4] bucket --- raindropGameCode/catcher.pde | 20 ++++++++++++++++++++ raindropGameCode/raindrop.pde | 26 +++++++++++++------------- raindropGameCode/raindropGameCode.pde | 10 +++++++--- 3 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 raindropGameCode/catcher.pde 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 index f82c881..a9fb07d 100644 --- a/raindropGameCode/raindrop.pde +++ b/raindropGameCode/raindrop.pde @@ -4,8 +4,8 @@ class Raindrop {// declaring all fields contained within Raindrop Class Raindrop(float x, float y) { diam = 30; loc= new PVector(x, y); - vel = new PVector(random(-5,5),random(-5,5)); - acc = new PVector(0, 0.3); + vel = new PVector(random(-3, 4), random(-3, 4)); + acc = new PVector(0, .2); } void display() { fill(253); @@ -16,19 +16,19 @@ class Raindrop {// declaring all fields contained within Raindrop Class loc.y=loc.y + vel.y; // add velocity to create fall vel.add(acc); //add gravity to the game } - void reset(){ - loc.y = 0; //reset the drops - vel.set(0,10); + void reset() { + loc.set(random(width),0); + vel.set(0,1); + acc.set(0,1); } 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; + 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 dc225ff..11e2da0 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,7 +1,7 @@ -int count=100; +int count=500; PVector mouse; //declare a P 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 @@ -9,15 +9,19 @@ Raindrop[] r = new Raindrop[count]; //declare a new Raindrop called r void setup() { size(1200, 800); + mouse = new PVector(); +c = new Catcher(50); for(int i = 0; i Date: Fri, 18 Dec 2015 14:45:24 -0500 Subject: [PATCH 4/4] arraylist --- raindropGameCode/raindrop.pde | 9 +++--- raindropGameCode/raindropGameCode.pde | 41 +++++++++++++++++---------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/raindropGameCode/raindrop.pde b/raindropGameCode/raindrop.pde index a9fb07d..f6efc62 100644 --- a/raindropGameCode/raindrop.pde +++ b/raindropGameCode/raindrop.pde @@ -4,8 +4,8 @@ class Raindrop {// declaring all fields contained within Raindrop Class Raindrop(float x, float y) { diam = 30; loc= new PVector(x, y); - vel = new PVector(random(-3, 4), random(-3, 4)); - acc = new PVector(0, .2); + vel = new PVector(random(-3, 3), random(-3, 3)); + acc = new PVector(0, .01); } void display() { fill(253); @@ -17,9 +17,8 @@ class Raindrop {// declaring all fields contained within Raindrop Class vel.add(acc); //add gravity to the game } void reset() { - loc.set(random(width),0); - vel.set(0,1); - acc.set(0,1); + 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 diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 11e2da0..fd0ac96 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,6 +1,7 @@ -int count=500; +int count=100; PVector mouse; //declare a P -Raindrop[] r = new Raindrop[count]; //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 @@ -12,25 +13,35 @@ void setup() { mouse = new PVector(); c = new Catcher(50); -for(int i = 0; i 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 - } + 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