From c39f9ff9fa9fe348b7cea5f6a6e15e6c9cc03237 Mon Sep 17 00:00:00 2001 From: Kingalinga Date: Tue, 15 Dec 2015 09:21:07 -0500 Subject: [PATCH 1/4] first commit --- raindropGameCode/raindropGameCode.pde | 63 +++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..7337116 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,6 +1,8 @@ +int count = 200; + PVector mouse; //declare a P Raindrop r; //declare a new Raindrop called r - +//Bucket b; // 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 @@ -15,12 +17,65 @@ void setup() { void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY background(0, 200, 255); + + //b.disp(); 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 (r.contact()) { //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 (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 } } + + + +class Raindrop { + PVector loc, vel, grav; + int diam; + color c; + Raindrop(float x, float y) { + loc = new PVector(x, y); + c = color(255); + vel = PVector.random2D(); + vel.mult(10); + diam= 30; + grav = new PVector(0, .5); + } + + void fall() { + vel= vel.add(grav); + loc.add(vel); + } + void display() { + fill(c); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); + } + void reset() { + loc.x=random(0, width); + loc.y=0; + vel = PVector.random2D(); + vel.mult(10); + vel= vel.add(grav); + loc.add(vel); + } + boolean contact(){ + boolean a; + if(loc.dist(mouse)>15){ + return true;} + +} +} +//class Bucket { +// PVector loc; +// Bucket() { +// loc= new PVector(mouseX, mouseY); + +// } +// void disp() { +// fill(50); +// rect(loc.x-40, loc.y-50, 80, 100); +// } +//} \ No newline at end of file From 40fbeb001bfd42b0706bbb79f2831da0f7ad5465 Mon Sep 17 00:00:00 2001 From: Kingalinga Date: Thu, 17 Dec 2015 08:42:33 -0500 Subject: [PATCH 2/4] added array --- raindropGameCode/raindropGameCode.pde | 66 ++++++++++++++------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 7337116..515be67 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,7 +1,8 @@ -int count = 200; +int count = 20; +Raindrop[] r= new Raindrop[count]; PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r +//Raindrop r; //declare a new Raindrop called r //Bucket b; // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object @@ -10,23 +11,35 @@ 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(); + //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} + int i=0; + while (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 + 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].contact(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 + } + i++; +} } @@ -41,7 +54,7 @@ class Raindrop { vel = PVector.random2D(); vel.mult(10); diam= 30; - grav = new PVector(0, .5); + grav = new PVector(0, .7); } void fall() { @@ -61,21 +74,12 @@ class Raindrop { vel= vel.add(grav); loc.add(vel); } - boolean contact(){ - boolean a; - if(loc.dist(mouse)>15){ - return true;} - -} -} -//class Bucket { -// PVector loc; -// Bucket() { -// loc= new PVector(mouseX, mouseY); - -// } -// void disp() { -// fill(50); -// rect(loc.x-40, loc.y-50, 80, 100); -// } -//} \ No newline at end of file + boolean contact(PVector bucket) { + loc.dist(mouse); + if (loc.dist(mouse) Date: Thu, 17 Dec 2015 09:21:59 -0500 Subject: [PATCH 3/4] Bucket is functioning --- raindropGameCode/Bucket.pde | 14 ++++++++++++++ raindropGameCode/raindropGameCode.pde | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 raindropGameCode/Bucket.pde diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde new file mode 100644 index 0000000..6f2e24a --- /dev/null +++ b/raindropGameCode/Bucket.pde @@ -0,0 +1,14 @@ +class Bucket { + PVector loc; + float diam; + Bucket(float tdiam) { + diam=tdiam; + loc=mouse; + } + void display() { + + + fill(255, 50, 150); + ellipse(mouseX, mouseY, diam, diam); + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 515be67..b0f777b 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,4 +1,5 @@ -int count = 20; +int count = 1500; +Bucket b= new Bucket(100); Raindrop[] r= new Raindrop[count]; PVector mouse; //declare a P @@ -40,6 +41,7 @@ while(i Date: Thu, 7 Jan 2016 08:00:04 -0500 Subject: [PATCH 4/4] Fixed the game! Finished the game and made all needed changes. --- raindropGameCode/Bucket.pde | 12 +-- raindropGameCode/raindropGameCode.pde | 86 +++++++-------- .../Bucket.pde | 15 +++ ...aindropGameCodeWithAttemptAtArrayLists.pde | 102 ++++++++++++++++++ 4 files changed, 164 insertions(+), 51 deletions(-) create mode 100644 raindropGameCodeWithAttemptAtArrayLists/Bucket.pde create mode 100644 raindropGameCodeWithAttemptAtArrayLists/raindropGameCodeWithAttemptAtArrayLists.pde diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde index 6f2e24a..4e28c0c 100644 --- a/raindropGameCode/Bucket.pde +++ b/raindropGameCode/Bucket.pde @@ -1,14 +1,14 @@ class Bucket { PVector loc; - float diam; + float diam; //creates a class "Bucket" with a float for diameter and vector for location Bucket(float tdiam) { - diam=tdiam; - loc=mouse; + diam=tdiam; //diameter can be chosen by the player before playing to increase difficulty(or decrease) + loc=mouse; //the location of the bucket is set to the vector"mouse" } void display() { +loc=mouse; - - fill(255, 50, 150); - ellipse(mouseX, mouseY, diam, diam); + fill(50, 240, 9); + ellipse(loc.x, loc.y, diam, diam); //creates a function to display the bucket as a green ball at the mouse location } } \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index b0f777b..5eb31cc 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,84 +1,80 @@ -int count = 1500; -Bucket b= new Bucket(100); -Raindrop[] r= new Raindrop[count]; - -PVector mouse; //declare a P -//Raindrop r; //declare a new Raindrop called r -//Bucket b; -// 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 - +int score1; //declares scoreing integer and initializes as "0" +Bucket b= new Bucket(5); // creates a bucket using the "Bucket" class and b as the name +ArrayList raindrops = new ArrayList(); //creates an array list for the class "raindrops" +PVector mouse; //creates a Pvector to use as the mouse location 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(){} - int i=0; - while (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 + raindrops.add(new Raindrop(random(width), 0)); //adds a new raindrop to the Arraylist for raindrops as "r" + for (int i = raindrops.size()-1; i >= 0; i--) { //keeps it from flashing the raindrops + Raindrop r = raindrops.get(i); //gets "r" from the Array List + r.display(); //uses the function to display the raindrops + r.fall(); //" to make the raindrops fall + if (r.contact(mouse)) { + r.reset(); // in the raindrop hits the bucket, it will reset back to the top + + score1++; //if the player hits a raindrop with the bucket, they score a point + if (r.loc.y > height + r.diam/2) { // if the raindrop goes below the screen, it goes back to the top + r.reset(); + } + } + textSize(50); + text(score1, width/2 - 50, 50); //>sets the text size, placement and sets it as the score of the game + textAlign(CENTER); + b.display(); //displays the bucket + if (score1> 50) { //if the score is greater than 50, the player see's a "win" screen + background(0); + textSize(50); + text("Congrats, You scored 50 Points!", width/2 - 50, 50); + textAlign(CENTER); + } } - i++; -} -b.display(); } class Raindrop { PVector loc, vel, grav; - int diam; + int diam; //creates the "raindrop" class by declaring the Pvectors "loc, vel and grav" snf the integer "diam" and the color"c" color c; - Raindrop(float x, float y) { + + Raindrop(float x, float y) { //shows that the raindrop class needs an x and a y float as a perameter loc = new PVector(x, y); c = color(255); - vel = PVector.random2D(); + vel = PVector.random2D(); //initializes loc as a new pvector with x and y, c as white, vel as a random vector, multiplies vel by 30, and adds gravity to the velocity vel.mult(10); diam= 30; grav = new PVector(0, .7); } void fall() { - vel= vel.add(grav); + vel= vel.add(grav); //function that adds grav to vel, or gravity to velocity, making it fall loc.add(vel); } void display() { fill(c); noStroke(); - ellipse(loc.x, loc.y, diam, diam); + ellipse(loc.x, loc.y, diam, diam); //displays the raindrops as ellipses at "x and y" using the variable "diam " as the diameter } void reset() { + loc.x=random(0, width); loc.y=0; - vel = PVector.random2D(); - vel.mult(10); - vel= vel.add(grav); + vel = new PVector(0, -4); //creates the reset function so that if it is started, it will put the raindrop to a random location at x=random y=0 + + vel= vel.add(grav); //also resets the gravity so it is not going too fast loc.add(vel); } boolean contact(PVector bucket) { loc.dist(mouse); - if (loc.dist(mouse) 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 +// } +// i++; +// } +// b.display(); + +// textSize(50); //setting text adjustments for the score 1 +// text(score1, width/2 - 50, 50); // " +// textAlign(CENTER); //" +} + + + +class Raindrop { + PVector loc, vel, grav; + int diam; + color c; + + Raindrop(float x, float y) { + loc = new PVector(x, y); + c = color(255); + vel = PVector.random2D(); + vel.mult(10); + diam= 30; + grav = new PVector(0, .7); + } + + void fall() { + vel= vel.add(grav); + loc.add(vel); + } + void display() { + fill(c); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); + } + void reset() { + + loc.x=random(0, width); + loc.y=0; + vel = new PVector(0, -4); + //vel.mult(10); + vel= vel.add(grav); + loc.add(vel); + } + boolean contact(PVector bucket) { + loc.dist(mouse); + if (loc.dist(mouse)