From f9b40cc9653e9d17f82c4ddb59415e2b6d2c87cb Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 15 Dec 2015 09:16:10 -0500 Subject: [PATCH 01/16] Did EVERYTHING! --- raindropGameCode/Raindrop.pde | 44 +++++++++++++++++++++++++++ raindropGameCode/raindropGameCode.pde | 32 +++++++++++++------ 2 files changed, 66 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..4a05bb0 --- /dev/null +++ b/raindropGameCode/Raindrop.pde @@ -0,0 +1,44 @@ +//declare class +class Raindrop { + + //declare vectors + PVector vel, loc, acc; + + //declare variables + float diam; + color c; + + Raindrop(){ //construct the raindrop object + diam = 30; + loc = new PVector(random(width),0); //define initial starting location of raindrops + vel = new PVector(0,0); //define initial speed of raindrops + acc = new PVector(0,.1); //define acceleration of raindrops' speed + + c = color(0,0,0); //define color of raindrops + } + + void display(){ + //color the raindrops + fill(c); + stroke(c); + ellipse(loc.x,loc.y,diam,diam); + } + + void reset() { + vel = new PVector(0, 0); + loc = new PVector(random(width), 0); + } + + void fall(){ + vel.add(acc); + loc.add(vel); + } + + boolean isInContactWith(PVector mouse) { + if (loc.dist(mouse) < diam/2) { + return true; + }else{ + return false; + } + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..7658b0b 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,5 +1,8 @@ +//define the number of raindrops the code will produce +int count = 1; + 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 @@ -9,18 +12,27 @@ 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 + + r[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions + + //draw a number of raindrops equal to the count interger + int i = 0; + while(i < count){ + i++; + } } 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 + 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) == true) { //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) { //check to see if the raindrop goes below the bottom of the screen + r[i].reset(); //if it does, 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 - } -} +} \ No newline at end of file From 49b1a6fcacec4bfb7f412042dd0644b321e0ec70 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 15 Dec 2015 09:19:18 -0500 Subject: [PATCH 02/16] Added random velocities and more raindrops --- raindropGameCode/Raindrop.pde | 6 +++--- raindropGameCode/raindropGameCode.pde | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index 4a05bb0..b24bb6b 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -11,10 +11,10 @@ class Raindrop { Raindrop(){ //construct the raindrop object diam = 30; loc = new PVector(random(width),0); //define initial starting location of raindrops - vel = new PVector(0,0); //define initial speed of raindrops + vel = new PVector(0,random(-10,10)); //define initial speed of raindrops acc = new PVector(0,.1); //define acceleration of raindrops' speed - c = color(0,0,0); //define color of raindrops + c = color(255); //define color of raindrops } void display(){ @@ -25,7 +25,7 @@ class Raindrop { } void reset() { - vel = new PVector(0, 0); + vel = new PVector(0, random(-10,10)); loc = new PVector(random(width), 0); } diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 7658b0b..e5d836e 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,5 +1,5 @@ //define the number of raindrops the code will produce -int count = 1; +int count = 900; PVector mouse; //declare a P Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r @@ -13,12 +13,9 @@ 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[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions - //draw a number of raindrops equal to the count interger - int i = 0; - while(i < count){ - i++; + for(int i = 0; i < count; i++){ + r[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions } } From 118ec48b7a80a8465bcb62b75d5a3958059846ec Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Thu, 17 Dec 2015 08:39:14 -0500 Subject: [PATCH 03/16] Began work on person, made raindrops stereotypically shaped --- raindropGameCode/Person.pde | 29 +++++++++++++++++++++++++++ raindropGameCode/Raindrop.pde | 1 + raindropGameCode/raindropGameCode.pde | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 raindropGameCode/Person.pde diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde new file mode 100644 index 0000000..1a77c7b --- /dev/null +++ b/raindropGameCode/Person.pde @@ -0,0 +1,29 @@ +class Person { + + //declare vectors + PVector pos, acc, vel; + + //declare variables + float diam; + color c; + + Person(){ + diam = 90; + pos = new PVector(width/2,height-diam); + vel = new PVector(0,0); + acc = new PVector(random(0.1),0); + + c = color(25,255,125); + } + + void display(){ + fill(c); + stroke(c); + ellipse(pos.x,pos.y, diam, diam); + } + + void move(){ + vel.add(acc); + pos.add(vel); + } +} \ No newline at end of file diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index b24bb6b..72dd491 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -22,6 +22,7 @@ class Raindrop { fill(c); stroke(c); ellipse(loc.x,loc.y,diam,diam); + triangle(loc.x - diam/2, loc.y, loc.x + diam/2, loc.y, loc.x, loc.y - diam); } void reset() { diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index e5d836e..f78f3a0 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,7 +1,7 @@ //define the number of raindrops the code will produce int count = 900; -PVector mouse; //declare a P +PVector mouse, posP; //declare a vector at the mouse and another for the person's position Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r // On your own, create an array of Raindrop objects instead of just one @@ -21,6 +21,7 @@ void setup() { void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + background(0, 200, 255); 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 From 9d6031a59981666776a202f149117173bebf3753 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Thu, 17 Dec 2015 08:41:55 -0500 Subject: [PATCH 04/16] Deleted code in useless tab --- raindropGameCode/Person.pde | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index 1a77c7b..e69de29 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -1,29 +0,0 @@ -class Person { - - //declare vectors - PVector pos, acc, vel; - - //declare variables - float diam; - color c; - - Person(){ - diam = 90; - pos = new PVector(width/2,height-diam); - vel = new PVector(0,0); - acc = new PVector(random(0.1),0); - - c = color(25,255,125); - } - - void display(){ - fill(c); - stroke(c); - ellipse(pos.x,pos.y, diam, diam); - } - - void move(){ - vel.add(acc); - pos.add(vel); - } -} \ No newline at end of file From d3a9d5ea68c465be19fe1666cfb4457628220414 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Thu, 17 Dec 2015 09:20:01 -0500 Subject: [PATCH 05/16] Edited bucket --- raindropGameCode/Bucket.pde | 25 +++++++++++++++++++++++ raindropGameCode/Person.pde | 29 +++++++++++++++++++++++++++ raindropGameCode/raindropGameCode.pde | 3 +++ 3 files changed, 57 insertions(+) create mode 100644 raindropGameCode/Bucket.pde diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde new file mode 100644 index 0000000..3a505d9 --- /dev/null +++ b/raindropGameCode/Bucket.pde @@ -0,0 +1,25 @@ +class Bucket{ + + //declare vector and variables + PVector loc; + float diam; + float c; + float wd; + float ht; + + Bucket(){ + diam = 80; + loc = new PVector(mouseX,mouseY); + + wd = 50; + ht = 60; + + c = color(25,165,165); + } + + void display(){ + fill(c); + stroke(c); + quad(loc.x - wd/2, loc.y - ht/2, loc.x + wd/2, loc.y - ht/2, loc.x - wd/2 + 5, loc.y + ht/2, loc.x + wd/2 - 5, loc.y + ht/2); + } +} \ No newline at end of file diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index e69de29..5d068f4 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -0,0 +1,29 @@ +class Person { + + //declare vectors + PVector loc, acc, vel; + + //declare variables + float diam; + color c; + + Person(){ + diam = 90; + loc = new PVector(width/2,height-diam); + vel = new PVector(0,0); + acc = new PVector(random(0.1),0); + + c = color(25,255,125); + } + + void display(){ + fill(c); + stroke(c); + ellipse(loc.x,loc.y, diam, diam); + } + + void move(){ + vel.add(acc); + loc.add(vel); + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index f78f3a0..f04027a 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -3,6 +3,7 @@ int count = 900; PVector mouse, posP; //declare a vector at the mouse and another for the person's position Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r +Bucket b = new Bucket(); // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object @@ -22,6 +23,8 @@ void setup() { void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + b.display(); + background(0, 200, 255); 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 From 6a1a4e35c174b57d8aca9384ca7ca6a6d966a544 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Thu, 17 Dec 2015 09:24:14 -0500 Subject: [PATCH 06/16] MoreStuff --- raindropGameCode/Bucket.pde | 7 ++++--- raindropGameCode/raindropGameCode.pde | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde index 3a505d9..82d1dbf 100644 --- a/raindropGameCode/Bucket.pde +++ b/raindropGameCode/Bucket.pde @@ -11,8 +11,8 @@ class Bucket{ diam = 80; loc = new PVector(mouseX,mouseY); - wd = 50; - ht = 60; + wd = 100; + ht = 80; c = color(25,165,165); } @@ -20,6 +20,7 @@ class Bucket{ void display(){ fill(c); stroke(c); - quad(loc.x - wd/2, loc.y - ht/2, loc.x + wd/2, loc.y - ht/2, loc.x - wd/2 + 5, loc.y + ht/2, loc.x + wd/2 - 5, loc.y + ht/2); + //quad(loc.x - wd/2, loc.y - ht/2, loc.x + wd/2, loc.y - ht/2, loc.x - wd/2 + 5, loc.y + ht/2, loc.x + wd/2 - 5, loc.y + ht/2); + quad(mouseX - wd/2, mouseY - ht/2, mouseX + wd/2, mouseY - ht/2, mouseX + wd/2 - 5, mouseY + ht/2, mouseX - wd/2 + 5, mouseY + ht/2); } } \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index f04027a..b2a0d06 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -23,8 +23,6 @@ void setup() { void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - b.display(); - background(0, 200, 255); 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 @@ -36,4 +34,6 @@ void draw() { r[i].reset(); //if it does, reset the raindrop } } + + b.display(); } \ No newline at end of file From c029326276197b529a3e92af2d8b1a8ce0818147 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Mon, 21 Dec 2015 08:53:41 -0500 Subject: [PATCH 07/16] Attempt to convert to ArrayList --- raindropGameCode/Bucket.pde | 3 +- raindropGameCode/Raindrop.pde | 10 +++++- raindropGameCode/raindropGameCode.pde | 51 +++++++++++++++++++-------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde index 82d1dbf..c8b96fa 100644 --- a/raindropGameCode/Bucket.pde +++ b/raindropGameCode/Bucket.pde @@ -22,5 +22,4 @@ class Bucket{ stroke(c); //quad(loc.x - wd/2, loc.y - ht/2, loc.x + wd/2, loc.y - ht/2, loc.x - wd/2 + 5, loc.y + ht/2, loc.x + wd/2 - 5, loc.y + ht/2); quad(mouseX - wd/2, mouseY - ht/2, mouseX + wd/2, mouseY - ht/2, mouseX + wd/2 - 5, mouseY + ht/2, mouseX - wd/2 + 5, mouseY + ht/2); - } -} \ No newline at end of file + } \ No newline at end of file diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index 72dd491..63c4162 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -42,4 +42,12 @@ class Raindrop { return false; } } -} \ No newline at end of file + + boolean onGround(){ + if (loc.y >= height){ + return true; + }else{ + return false; + } + } +}} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index b2a0d06..a56905c 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -2,7 +2,11 @@ int count = 900; PVector mouse, posP; //declare a vector at the mouse and another for the person's position -Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r + +//Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r + +ArrayList r = new ArrayList(); + Bucket b = new Bucket(); // On your own, create an array of Raindrop objects instead of just one @@ -13,27 +17,46 @@ Bucket b = new Bucket(); 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(){} - - //draw a number of raindrops equal to the count interger - for(int i = 0; i < count; i++){ - r[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions - } + r.add(new Raindrop()); + ////draw a number of raindrops equal to the count interger + //for(int i = r.size() - 1; i >= 0; i--){ + // //r[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions + // Raindrop rain = r.get(); + // rain.display(); + // rain.fall(); + // if(rain.onGround()){ + // rain.remove(i); + // } + //} } void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY background(0, 200, 255); - 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) == true) { //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) { //check to see if the raindrop goes below the bottom of the screen - r[i].reset(); //if it does, reset the raindrop + + r.add(new Raindrop()); + //draw a number of raindrops equal to the count interger + for(int i = r.size() - 1; i >= 0; i--){ + //r[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions + Raindrop rain = r.get(); + rain.display(); + rain.fall(); + if(rain.onGround()){ + rain.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) == true) { //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) { //check to see if the raindrop goes below the bottom of the screen + // r[i].reset(); //if it does, reset the raindrop + // } + //} + b.display(); } \ No newline at end of file From 13e1f84939c89efa87dae70df5f578a7c330b529 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 08:17:21 -0500 Subject: [PATCH 08/16] Created space for "hitbox" class --- raindropGameCode/Hitbox.pde | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 raindropGameCode/Hitbox.pde diff --git a/raindropGameCode/Hitbox.pde b/raindropGameCode/Hitbox.pde new file mode 100644 index 0000000..e69de29 From e95ed0dc74713e2e325f6b854ddcfed0238af612 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 08:49:49 -0500 Subject: [PATCH 09/16] HAAAAAAAAAAAAAANS xkcd references spawn from instances of immense coding confusion --- raindropGameCode/Hitbox.pde | 0 raindropGameCode/Person.pde | 5 ++- raindropGameCode/Raindrop.pde | 53 +++++++++++++++------------ raindropGameCode/raindropGameCode.pde | 4 +- 4 files changed, 34 insertions(+), 28 deletions(-) delete mode 100644 raindropGameCode/Hitbox.pde diff --git a/raindropGameCode/Hitbox.pde b/raindropGameCode/Hitbox.pde deleted file mode 100644 index e69de29..0000000 diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index 5d068f4..4c3b8c5 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -23,7 +23,8 @@ class Person { } void move(){ - vel.add(acc); - loc.add(vel); + //create method to move the person based on their random acceleration + vel.add(acc); //add acceleration to the velocity + loc.add(vel); //add velocity to the position } } \ No newline at end of file diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index 63c4162..ffd6252 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -1,53 +1,58 @@ //declare class class Raindrop { - + //declare vectors PVector vel, loc, acc; - + //declare variables float diam; color c; - - Raindrop(){ //construct the raindrop object + + Raindrop() { //construct the raindrop object diam = 30; - loc = new PVector(random(width),0); //define initial starting location of raindrops - vel = new PVector(0,random(-10,10)); //define initial speed of raindrops - acc = new PVector(0,.1); //define acceleration of raindrops' speed - + loc = new PVector(random(width), -20); //define initial starting location of raindrops + vel = new PVector(0, random(-10, 10)); //define initial speed of raindrops + acc = new PVector(0, .1); //define acceleration of raindrops' speed + c = color(255); //define color of raindrops } - - void display(){ + + void display() { //color the raindrops fill(c); stroke(c); - ellipse(loc.x,loc.y,diam,diam); - triangle(loc.x - diam/2, loc.y, loc.x + diam/2, loc.y, loc.x, loc.y - diam); + + //draw the ellipse that composes the raindrops + ellipse(loc.x, loc.y, diam, diam); } - + void reset() { - vel = new PVector(0, random(-10,10)); - loc = new PVector(random(width), 0); + //create method to reset the raindrops' position and speed + vel = new PVector(0, random(-10, 10)); + loc = new PVector(random(width), -20); } - void fall(){ + void fall() { + //create method to cause the raindrops to fall vel.add(acc); loc.add(vel); } - boolean isInContactWith(PVector mouse) { - if (loc.dist(mouse) < diam/2) { + boolean isInContactWith(int x1, int x2, int y1, int y2) { + //create boolean to return "true" if the raindrop's location lies within the four given points. + if (loc.x >= x1 && loc.x <= x2 && loc.y >= y1 && loc.y <= y2) { return true; - }else{ + } else { return false; } } - - boolean onGround(){ - if (loc.y >= height){ + + boolean onGround() { + if (loc.y >= height) { return true; - }else{ + } else { return false; } } -}} \ No newline at end of file +} +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index a56905c..f844d2c 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,7 +1,7 @@ //define the number of raindrops the code will produce int count = 900; -PVector mouse, posP; //declare a vector at the mouse and another for the person's position +PVector mouse; //declare a vector at the mouse //Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r @@ -50,7 +50,7 @@ void draw() { //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) == true) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + // if (r[i].isInContactWith(b.loc.x - (b.wd / 2), b.loc.x + (b.wd / 2), b.loc.y - (b.ht / 2), b.loc.y + (b.wd / 2)) == true) { //check to see if the raindrop is in contact with the bucket by determining if it lies within the space occupied by the bucket // r[i].reset(); //if it is, reset the raindrop // } // if (r[i].loc.y > height) { //check to see if the raindrop goes below the bottom of the screen From bc56471f2135685ae4da0b98d833525a2d5fe301 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 09:09:32 -0500 Subject: [PATCH 10/16] UNDERSTANDING Comments, bug fixes, fun times --- raindropGameCode/Bucket.pde | 28 ++++++++-------- raindropGameCode/Person.pde | 6 ++-- raindropGameCode/Raindrop.pde | 5 +-- raindropGameCode/raindropGameCode.pde | 46 ++++++++++----------------- 4 files changed, 37 insertions(+), 48 deletions(-) diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde index c8b96fa..e18d5fe 100644 --- a/raindropGameCode/Bucket.pde +++ b/raindropGameCode/Bucket.pde @@ -1,25 +1,27 @@ -class Bucket{ - +class Bucket { + //declare vector and variables PVector loc; float diam; float c; float wd; float ht; - - Bucket(){ + + Bucket() { diam = 80; - loc = new PVector(mouseX,mouseY); - + loc = new PVector(mouseX, mouseY); + wd = 100; - ht = 80; - - c = color(25,165,165); + ht = 20; + + c = color(25, 165, 165); } - - void display(){ + + void display() { + //color the bucket interior and background as determined by the floated variable "c" fill(c); stroke(c); - //quad(loc.x - wd/2, loc.y - ht/2, loc.x + wd/2, loc.y - ht/2, loc.x - wd/2 + 5, loc.y + ht/2, loc.x + wd/2 - 5, loc.y + ht/2); + //display the bucket centered at the mouse quad(mouseX - wd/2, mouseY - ht/2, mouseX + wd/2, mouseY - ht/2, mouseX + wd/2 - 5, mouseY + ht/2, mouseX - wd/2 + 5, mouseY + ht/2); - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index 4c3b8c5..bf782e7 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -8,10 +8,10 @@ class Person { color c; Person(){ - diam = 90; - loc = new PVector(width/2,height-diam); + diam = 50; + loc = new PVector(600,800 - diam / 2); vel = new PVector(0,0); - acc = new PVector(random(0.1),0); + acc = new PVector(random(-0.1,0.1),0); c = color(25,255,125); } diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index ffd6252..fdcb8bf 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -30,6 +30,8 @@ class Raindrop { //create method to reset the raindrops' position and speed vel = new PVector(0, random(-10, 10)); loc = new PVector(random(width), -20); + //increase acceleration of raindrops every time they are reset + acc.mult(1.5); } void fall() { @@ -38,7 +40,7 @@ class Raindrop { loc.add(vel); } - boolean isInContactWith(int x1, int x2, int y1, int y2) { + boolean isInContactWith(float x1, float x2, float y1, float y2) { //create boolean to return "true" if the raindrop's location lies within the four given points. if (loc.x >= x1 && loc.x <= x2 && loc.y >= y1 && loc.y <= y2) { return true; @@ -54,5 +56,4 @@ class Raindrop { return false; } } -} } \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index f844d2c..bd76456 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,5 +1,5 @@ //define the number of raindrops the code will produce -int count = 900; +int count = 1; PVector mouse; //declare a vector at the mouse @@ -9,6 +9,8 @@ ArrayList r = new ArrayList(); Bucket b = new Bucket(); +Person p = new Person(); + // 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 @@ -18,45 +20,29 @@ 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.add(new Raindrop()); - ////draw a number of raindrops equal to the count interger - //for(int i = r.size() - 1; i >= 0; i--){ - // //r[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions - // Raindrop rain = r.get(); - // rain.display(); - // rain.fall(); - // if(rain.onGround()){ - // rain.remove(i); - // } - //} } void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - + background(0, 200, 255); - + r.add(new Raindrop()); //draw a number of raindrops equal to the count interger - for(int i = r.size() - 1; i >= 0; i--){ - //r[i] = new Raindrop(); //Initialize r. The parameters used are the initial x and y positions - Raindrop rain = r.get(); + for (int i = r.size() - 1; i >= 0; i--) { + Raindrop rain = r.get(i); rain.display(); rain.fall(); - if(rain.onGround()){ - rain.remove(i); + if (rain.onGround()) { + r.remove(i); + } + if (rain.isInContactWith(mouseX - (b.wd / 2), mouseX + (b.wd / 2), mouseY - (b.ht / 2), mouseY + (b.wd / 2))) { + r.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(b.loc.x - (b.wd / 2), b.loc.x + (b.wd / 2), b.loc.y - (b.ht / 2), b.loc.y + (b.wd / 2)) == true) { //check to see if the raindrop is in contact with the bucket by determining if it lies within the space occupied by the bucket - // r[i].reset(); //if it is, reset the raindrop - // } - // if (r[i].loc.y > height) { //check to see if the raindrop goes below the bottom of the screen - // r[i].reset(); //if it does, reset the raindrop - // } - //} - + b.display(); + + p.display(); + p. move(); } \ No newline at end of file From f0c7df1827649ee5ca3aa2081e071bd0eeaa4b62 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 09:21:11 -0500 Subject: [PATCH 11/16] Thing Thing --- raindropGameCode/raindropGameCode.pde | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index bd76456..e861afc 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,9 +1,5 @@ -//define the number of raindrops the code will produce -int count = 1; - -PVector mouse; //declare a vector at the mouse - -//Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r +//declare integers for the person's health, what menu is open, and what score is seen +int menu, health, score; ArrayList r = new ArrayList(); @@ -11,19 +7,15 @@ Bucket b = new Bucket(); Person p = new Person(); -// 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() { size(1200, 800); - mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} r.add(new Raindrop()); + health = 10; } void draw() { - mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + //mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY background(0, 200, 255); @@ -39,10 +31,16 @@ void draw() { if (rain.isInContactWith(mouseX - (b.wd / 2), mouseX + (b.wd / 2), mouseY - (b.ht / 2), mouseY + (b.wd / 2))) { r.remove(i); } + if (rain.isInContactWith(p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2), p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2))) { + r.remove(i); + health --; + } } + //draw the bucket at the given location b.display(); - p.display(); + //draw the + p.display(); p. move(); } \ No newline at end of file From 2a72051498a5e067f1c3b4bf8d82ed6d2e509d7a Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 09:23:35 -0500 Subject: [PATCH 12/16] Fhtagn Ia! Dagon! (More code was written) --- raindropGameCode/Person.pde | 28 +++++++++++++-------------- raindropGameCode/raindropGameCode.pde | 4 +++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index bf782e7..1a2c470 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -1,28 +1,28 @@ class Person { - + //declare vectors PVector loc, acc, vel; - + //declare variables float diam; color c; - - Person(){ + + Person() { diam = 50; - loc = new PVector(600,800 - diam / 2); - vel = new PVector(0,0); - acc = new PVector(random(-0.1,0.1),0); - - c = color(25,255,125); + loc = new PVector(600, 800 - diam / 2); + vel = new PVector(0, 0); + acc = new PVector(random(-0.1, 0.1), 0); + + c = color(25, 255, 125); } - - void display(){ + + void display() { fill(c); stroke(c); - ellipse(loc.x,loc.y, diam, diam); + ellipse(loc.x, loc.y, diam, diam); } - - void move(){ + + void move() { //create method to move the person based on their random acceleration vel.add(acc); //add acceleration to the velocity loc.add(vel); //add velocity to the position diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index e861afc..75aeb2c 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -40,7 +40,9 @@ void draw() { //draw the bucket at the given location b.display(); - //draw the + //draw the person at the given location p.display(); + + //cause the person to move p. move(); } \ No newline at end of file From 8b0fc095b7d34a1e055b74e6a0bc6860e6c6023c Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 17:10:17 -0500 Subject: [PATCH 13/16] Thing! Thing. --- raindropGameCode/raindropGameCode.pde | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 75aeb2c..16d1b26 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -9,14 +9,22 @@ Person p = new Person(); void setup() { - size(1200, 800); - r.add(new Raindrop()); + //set canvas size + size(1200, 800); + + //color background + background(0, 200, 255); + + //set initial score and health health = 10; + score = 0; + + //set initial menu to the start menu. + menu = 0; } void draw() { - //mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - + //draw background background(0, 200, 255); r.add(new Raindrop()); @@ -45,4 +53,17 @@ void draw() { //cause the person to move p. move(); + + //Create scoreboard at top of screen + fill(255); + rectMode(CENTER); + noStroke(); + rect(width/2, 29, 240, 60); + + //write text on scoreboard + textSize(20); + fill(0, 200, 255); + textMode(CENTER); + text("HEALTH: " + health, width/2, 15); + text("DROPS CAUGHT: " + score, width/2, 45); } \ No newline at end of file From 289e701703034c5929cca144ac02360c4e410adf Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 21:18:25 -0500 Subject: [PATCH 14/16] Commenting! --- raindropGameCode/Bucket.pde | 6 ++++-- raindropGameCode/Person.pde | 6 +++++- raindropGameCode/Raindrop.pde | 7 ++++++- raindropGameCode/raindropGameCode.pde | 28 ++++++++++++++++++++++++--- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde index e18d5fe..717a932 100644 --- a/raindropGameCode/Bucket.pde +++ b/raindropGameCode/Bucket.pde @@ -2,18 +2,20 @@ class Bucket { //declare vector and variables PVector loc; - float diam; float c; float wd; float ht; + //declare Bucket class Bucket() { - diam = 80; + //define location of bucket loc = new PVector(mouseX, mouseY); + //define dimensions of bucket wd = 100; ht = 20; + //define color of bucket c = color(25, 165, 165); } diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index 1a2c470..7985048 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -7,11 +7,15 @@ class Person { float diam; color c; + //define Person class Person() { + //define diameter of ellipse diam = 50; + + //define variables for movement: location, velocity and acceleration loc = new PVector(600, 800 - diam / 2); vel = new PVector(0, 0); - acc = new PVector(random(-0.1, 0.1), 0); + acc = new PVector(random(1, 0); c = color(25, 255, 125); } diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index fdcb8bf..75e58f5 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -9,12 +9,16 @@ class Raindrop { color c; Raindrop() { //construct the raindrop object + //set raindrop diameter diam = 30; + + //define variables for movement: location, velocity and acceleration loc = new PVector(random(width), -20); //define initial starting location of raindrops vel = new PVector(0, random(-10, 10)); //define initial speed of raindrops acc = new PVector(0, .1); //define acceleration of raindrops' speed - c = color(255); //define color of raindrops + //define color of raindrops + c = color(255); } void display() { @@ -50,6 +54,7 @@ class Raindrop { } boolean onGround() { + //create boolean to return "true" if the raindrop's location lies upon the lower edge of the canvas if (loc.y >= height) { return true; } else { diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 16d1b26..0dbb606 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,6 +1,7 @@ //declare integers for the person's health, what menu is open, and what score is seen int menu, health, score; +//create arraylist of raindrops to create many raindrops on-screen ArrayList r = new ArrayList(); Bucket b = new Bucket(); @@ -27,18 +28,32 @@ void draw() { //draw background background(0, 200, 255); + if(menu == 0){ //create the start menu + + }else if(menu == 1){ //create space for the game itself + + }else if(menu == 2){ //create the game over menu + + } + r.add(new Raindrop()); //draw a number of raindrops equal to the count interger for (int i = r.size() - 1; i >= 0; i--) { - Raindrop rain = r.get(i); - rain.display(); - rain.fall(); + Raindrop rain = r.get(i); //retrieve a raindrop object + rain.display(); //display the raindrops + rain.fall(); //cause the raindrops to fall + + //if the raindrops hit the ground, remove them from the canvas if (rain.onGround()) { r.remove(i); } + + //if the raindrops hit the bucket, remove them and increase the score by 1 if (rain.isInContactWith(mouseX - (b.wd / 2), mouseX + (b.wd / 2), mouseY - (b.ht / 2), mouseY + (b.wd / 2))) { r.remove(i); } + + //if the raindrops hit the person, remove them and decrease health by 1 if (rain.isInContactWith(p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2), p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2))) { r.remove(i); health --; @@ -51,6 +66,13 @@ void draw() { //draw the person at the given location p.display(); + //change acceleration of Person class every frame + p.acc.mult(random(-.1, .1)); + + if(){ + + } + //cause the person to move p. move(); From ae3599509775e0b7eabcec44b0a3daa25ea08d40 Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Tue, 5 Jan 2016 22:14:23 -0500 Subject: [PATCH 15/16] Yaay More documentation --- raindropGameCode/Person.pde | 6 ++-- raindropGameCode/raindropGameCode.pde | 40 ++++++++++++++------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index 7985048..f466122 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -7,15 +7,15 @@ class Person { float diam; color c; - //define Person class + //define Person class Person() { //define diameter of ellipse diam = 50; - + //define variables for movement: location, velocity and acceleration loc = new PVector(600, 800 - diam / 2); vel = new PVector(0, 0); - acc = new PVector(random(1, 0); + acc = new PVector(random(1, 0)); c = color(25, 255, 125); } diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 0dbb606..84396e1 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -12,14 +12,14 @@ Person p = new Person(); void setup() { //set canvas size size(1200, 800); - + //color background background(0, 200, 255); - + //set initial score and health health = 10; score = 0; - + //set initial menu to the start menu. menu = 0; } @@ -28,31 +28,28 @@ void draw() { //draw background background(0, 200, 255); - if(menu == 0){ //create the start menu - - }else if(menu == 1){ //create space for the game itself - - }else if(menu == 2){ //create the game over menu - + if (menu == 0) { //create the start menu + } else if (menu == 1) { //create space for the game itself + } else if (menu == 2) { //create the game over menu } - + r.add(new Raindrop()); //draw a number of raindrops equal to the count interger for (int i = r.size() - 1; i >= 0; i--) { Raindrop rain = r.get(i); //retrieve a raindrop object rain.display(); //display the raindrops rain.fall(); //cause the raindrops to fall - + //if the raindrops hit the ground, remove them from the canvas if (rain.onGround()) { r.remove(i); } - + //if the raindrops hit the bucket, remove them and increase the score by 1 if (rain.isInContactWith(mouseX - (b.wd / 2), mouseX + (b.wd / 2), mouseY - (b.ht / 2), mouseY + (b.wd / 2))) { r.remove(i); } - + //if the raindrops hit the person, remove them and decrease health by 1 if (rain.isInContactWith(p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2), p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2))) { r.remove(i); @@ -66,13 +63,18 @@ void draw() { //draw the person at the given location p.display(); - //change acceleration of Person class every frame + //change acceleration of Person class every frame p.acc.mult(random(-.1, .1)); - - if(){ - + + //if the person hits the edge of the canvas, change direction + if (p.loc.x >= width) { + p.vel.mult(-1); + p.loc.x = width; + }else if(p.loc.x <= 0){ + p.vel.mult(-1); + p.loc.x = 0; } - + //cause the person to move p. move(); @@ -81,7 +83,7 @@ void draw() { rectMode(CENTER); noStroke(); rect(width/2, 29, 240, 60); - + //write text on scoreboard textSize(20); fill(0, 200, 255); From 777d753c6c47ca531aa303688d2573886180a86e Mon Sep 17 00:00:00 2001 From: JMuad-Dib Date: Wed, 6 Jan 2016 11:37:12 -0500 Subject: [PATCH 16/16] Done! That. --- raindropGameCode/Person.pde | 4 +- raindropGameCode/raindropGameCode.pde | 142 +++++++++++++++++--------- 2 files changed, 94 insertions(+), 52 deletions(-) diff --git a/raindropGameCode/Person.pde b/raindropGameCode/Person.pde index f466122..68c2018 100644 --- a/raindropGameCode/Person.pde +++ b/raindropGameCode/Person.pde @@ -15,12 +15,14 @@ class Person { //define variables for movement: location, velocity and acceleration loc = new PVector(600, 800 - diam / 2); vel = new PVector(0, 0); - acc = new PVector(random(1, 0)); + acc = new PVector(.1, 0); + //color the person c = color(25, 255, 125); } void display() { + //create method to draw the person fill(c); stroke(c); ellipse(loc.x, loc.y, diam, diam); diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 84396e1..df4db12 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -25,69 +25,109 @@ void setup() { } void draw() { - //draw background - background(0, 200, 255); if (menu == 0) { //create the start menu + //draw background every frame + background(0, 200, 255); + + //write start menu text + textSize(120); + fill(255); + textAlign(CENTER); + text("RAINDROP BULWARK", width/2, 300); + textSize(40); + text("USE THE MOUSE TO SHIELD THE PERSON FROM THE RAIN!", width/2, 500); + text("PRESS 'R' TO START", width/2, 700); + } else if (menu == 1) { //create space for the game itself - } else if (menu == 2) { //create the game over menu - } + //draw background every frame + background(0, 200, 255); + + r.add(new Raindrop()); + //draw a number of raindrops equal to the count interger + for (int i = r.size() - 1; i >= 0; i--) { + Raindrop rain = r.get(i); //retrieve a raindrop object + rain.display(); //display the raindrops + rain.fall(); //cause the raindrops to fall + + //if the raindrops hit the ground, remove them from the canvas + if (rain.onGround()) { + r.remove(i); + } + + //if the raindrops hit the bucket, remove them and increase the score by 1 + if (rain.isInContactWith(mouseX - (b.wd / 2), mouseX + (b.wd / 2), mouseY - (b.ht / 2), mouseY + (b.wd / 2))) { + r.remove(i); + score ++; + } + + //if the raindrops hit the person, remove them and decrease health by 1 + if (rain.isInContactWith(p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2), p.loc.y - (p.diam / 2), p.loc.y + (p.diam / 2))) { + r.remove(i); + health --; + } + } - r.add(new Raindrop()); - //draw a number of raindrops equal to the count interger - for (int i = r.size() - 1; i >= 0; i--) { - Raindrop rain = r.get(i); //retrieve a raindrop object - rain.display(); //display the raindrops - rain.fall(); //cause the raindrops to fall + //draw the bucket at the given location + b.display(); - //if the raindrops hit the ground, remove them from the canvas - if (rain.onGround()) { - r.remove(i); - } + //draw the person at the given location + p.display(); - //if the raindrops hit the bucket, remove them and increase the score by 1 - if (rain.isInContactWith(mouseX - (b.wd / 2), mouseX + (b.wd / 2), mouseY - (b.ht / 2), mouseY + (b.wd / 2))) { - r.remove(i); - } + //change acceleration of Person class every frame + p.acc.mult(random(-2, 2)); - //if the raindrops hit the person, remove them and decrease health by 1 - if (rain.isInContactWith(p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2), p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2))) { - r.remove(i); - health --; + //if the person hits the edge of the canvas, change direction + if (p.loc.x > width) { + p.vel.mult(-1); + p.loc.x = width; + } else if (p.loc.x < 0) { + p.vel.mult(-1); + p.loc.x = 0; } + + //cause the person to move + p. move(); + + //Create scoreboard at top of screen + fill(255); + rectMode(CENTER); + noStroke(); + rect(width/2, 29, 240, 60); + + //write text on scoreboard + textSize(20); + fill(0, 200, 255); + textAlign(CENTER); + text("HEALTH: " + health, width/2, 15); + text("DROPS CAUGHT: " + score, width/2, 45); + + } else if (menu == 2) { //create the game over menu + //draw background every frame + background(0, 200, 255); + + //write GAME OVER text + textAlign(CENTER); + fill(255); + textSize(120); + text("GAME OVER", width/2, 300); + text("YOUR SCORE: " + score, width/2, 500); + text("PRESS 'R' TO START", width/2, 700); } - //draw the bucket at the given location - b.display(); - //draw the person at the given location - p.display(); - //change acceleration of Person class every frame - p.acc.mult(random(-.1, .1)); - //if the person hits the edge of the canvas, change direction - if (p.loc.x >= width) { - p.vel.mult(-1); - p.loc.x = width; - }else if(p.loc.x <= 0){ - p.vel.mult(-1); - p.loc.x = 0; + //if the r-key is pressed, restart the game + if (keyPressed == true) { + if (key == 'r' || key == 'R') { + menu = 1; + health = 10; + score = 0; + } + } + + if(health == 0){ + menu = 2; } - - //cause the person to move - p. move(); - - //Create scoreboard at top of screen - fill(255); - rectMode(CENTER); - noStroke(); - rect(width/2, 29, 240, 60); - - //write text on scoreboard - textSize(20); - fill(0, 200, 255); - textMode(CENTER); - text("HEALTH: " + health, width/2, 15); - text("DROPS CAUGHT: " + score, width/2, 45); } \ No newline at end of file