From 3d97f15bf8398ef08032832b75ad93a901476f1b Mon Sep 17 00:00:00 2001 From: daena94 Date: Mon, 14 Dec 2015 13:23:09 -0500 Subject: [PATCH 1/9] started raindrop game --- raindropGameCode/Raindrop.pde | 44 +++++++++++++++++++++++++++ raindropGameCode/raindropGameCode.pde | 4 +-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 raindropGameCode/Raindrop.pde diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde new file mode 100644 index 0000000..91a857b --- /dev/null +++ b/raindropGameCode/Raindrop.pde @@ -0,0 +1,44 @@ +class Raindrop { + PVector loc, vel; + int r, diam; + + + +Raindrop(float x,float y) { + diam = 100; + loc = new PVector(random(diam,width-diam), random(diam,height-diam)); + vel = PVector.random2D(); + vel.mult(10); +} + + +void display() { + fill(255); + noStroke(); + ellipse(loc.x,loc.y,diam,diam); +} + +void move() { + loc.add(vel); +} + +void run(){ + display(); + move(); +} +void fall() { + +} +boolean isInContactWith(PVector mouse) { + if (dist(mouse.x,mouse.y,loc.x,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 ee7193be14a6bb13955c566d4a4b7e3c50f47d4c Mon Sep 17 00:00:00 2001 From: daena94 Date: Tue, 15 Dec 2015 12:32:39 -0500 Subject: [PATCH 2/9] made raindrop game --- raindropGameCode/Raindrop.pde | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index 91a857b..54cd302 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -1,14 +1,15 @@ class Raindrop { - PVector loc, vel; + PVector loc, vel, a; int r, diam; Raindrop(float x,float y) { diam = 100; - loc = new PVector(random(diam,width-diam), random(diam,height-diam)); - vel = PVector.random2D(); - vel.mult(10); + loc = new PVector(random(diam,width-diam), 0); + vel = new PVector(0,random(1,10)); + a = new PVector(0,0.001); + } @@ -18,17 +19,11 @@ void display() { ellipse(loc.x,loc.y,diam,diam); } -void move() { +void fall() { loc.add(vel); + vel.add(a); } -void run(){ - display(); - move(); -} -void fall() { - -} boolean isInContactWith(PVector mouse) { if (dist(mouse.x,mouse.y,loc.x,loc.y) Date: Tue, 15 Dec 2015 13:23:53 -0500 Subject: [PATCH 3/9] started bucket challenge --- raindropGameCode/Catcher.pde | 28 +++++++++++++++++++++++++++ raindropGameCode/Raindrop.pde | 2 +- raindropGameCode/raindropGameCode.pde | 14 ++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 raindropGameCode/Catcher.pde diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde new file mode 100644 index 0000000..0ad9d77 --- /dev/null +++ b/raindropGameCode/Catcher.pde @@ -0,0 +1,28 @@ +class Catcher { + PVector loc; + int diam, b; + + Catcher(float x, float y) { + x = mouseX; + y = mouseY; + diam = 100; + loc = new PVector(mouseX, mouseY); + } + + void bucket(float x, float y) { + fill(0); + ellipse(x, y, diam, diam); + noStroke(); + } + boolean isInContactWith(Catcher b) { + if (loc.dist(b.loc) height + r.diam/2) { //check to see if the raindrop goes below the bottom of the screen From 56ddc1e1dc254c98a131dbb0a81c764359057200 Mon Sep 17 00:00:00 2001 From: daena94 Date: Thu, 7 Jan 2016 11:51:17 -0500 Subject: [PATCH 4/9] started array list --- raindropGameCode/Catcher.pde | 19 ++++------ raindropGameCode/Raindrop.pde | 52 +++++++++++++-------------- raindropGameCode/raindropGameCode.pde | 32 +++++++++-------- 3 files changed, 50 insertions(+), 53 deletions(-) diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde index 0ad9d77..19ef358 100644 --- a/raindropGameCode/Catcher.pde +++ b/raindropGameCode/Catcher.pde @@ -1,12 +1,10 @@ class Catcher { PVector loc; - int diam, b; + int diam, b, c; - Catcher(float x, float y) { - x = mouseX; - y = mouseY; + Catcher(float w, float v) { diam = 100; - loc = new PVector(mouseX, mouseY); + loc = new PVector(w, v); } void bucket(float x, float y) { @@ -14,15 +12,12 @@ class Catcher { ellipse(x, y, diam, diam); noStroke(); } - boolean isInContactWith(Catcher b) { - if (loc.dist(b.loc) r = new ArrayList(); PVector circle; //declare a PVector called mouse -Raindrop r;//declare a new Raindrop called r -Catcher 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 +Catcher c; void setup() { size(1200, 800); circle = 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 - b = new Catcher(mouseX, mouseY); + r.add(new Raindrop(random(width), 0)); + c = new Catcher(random(width), 0); } void draw() { circle.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 - b.bucket(mouseX, mouseY); - if (r.isInContactWith(circle)) { //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 + r.add(new Raindrop(random(width), 0)); + c.bucket(mouseX, mouseY); + c.update(); + for (int i = r.size()-1; i>=0; i--) { + Raindrop d= r.get(i); + d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + d.display(); //display the raindrop + if (d.isInContactWith(c.loc)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + r.remove(i); //if it is, reset the raindrop + } + if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen + r.remove(i); //if it does, reset the raindrop + } } } \ No newline at end of file From 1f9d2e4f6ec231d391a80e1d6c25d7127de00ed1 Mon Sep 17 00:00:00 2001 From: daena94 Date: Thu, 7 Jan 2016 21:33:12 -0500 Subject: [PATCH 5/9] almost done --- raindropGameCode/Catcher.pde | 2 +- raindropGameCode/Raindrop.pde | 58 +++++++++++--- raindropGameCode/raindropGameCode.pde | 105 +++++++++++++++++++++----- 3 files changed, 134 insertions(+), 31 deletions(-) diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde index 19ef358..17bc1fb 100644 --- a/raindropGameCode/Catcher.pde +++ b/raindropGameCode/Catcher.pde @@ -20,4 +20,4 @@ class Catcher { void update(){ loc.set(mouseX,mouseY); } -} \ No newline at end of file +} diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index c711f00..39531f8 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -1,32 +1,43 @@ class Raindrop { - PVector loc, vel, a; + PVector loc, vel; int r, diam; + float gravity; + color a, b, c, d; + float ran; + boolean yes = false; - - - Raindrop(float x, float y) { + Raindrop(float w, float v) { diam = 50; - loc = new PVector(random(diam, width-diam), 0); - vel = new PVector(0, random(1, 10)); - a = new PVector(0, 0.001); + loc = new PVector(w, v); + a = color(255); + b = color(255, 0, 0); + c = color(0, 255, 0); + d = color(0, 0, 255); + vel = PVector.random2D(); + vel.mult(20); + gravity = random(.2, .8); + ran = random(0, 1); } void display() { - fill(255); + fill(a); noStroke(); ellipse(loc.x, loc.y, diam, diam); } void fall() { - loc.add(vel); - vel.add(a); + loc.y+=vel.y; + if (loc.y<=height) { + vel.ye+=gravity; + } } boolean isInContactWith(Catcher c) { if (c.loc.dist(loc).25 && ran<.5) { + a=b; + } + if (ran>.5 && ran<.75) { + a=c; + } + if (ran>.75) { + a=d; + } } -} \ No newline at end of file + + boolean y() { + if (a==a) { + return true; + } + else { + return false; + } + } +} + diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 3c8d319..cedc2ad 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,30 +1,99 @@ ArrayList r = new ArrayList(); -PVector circle; //declare a PVector called mouse +PVector mouse; //declare a PVector called mouse Catcher c; - +int count = 10; +int mode = 0; +int t = 0; +int s = 0; void setup() { size(1200, 800); - circle = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} + mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} r.add(new Raindrop(random(width), 0)); - c = new Catcher(random(width), 0); + c = new Catcher(width/2, height/2); } void draw() { - circle.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - background(0, 200, 255); - r.add(new Raindrop(random(width), 0)); - c.bucket(mouseX, mouseY); - c.update(); - for (int i = r.size()-1; i>=0; i--) { - Raindrop d= r.get(i); - d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - d.display(); //display the raindrop - if (d.isInContactWith(c.loc)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - r.remove(i); //if it is, reset the raindrop + if (mode==0) { + background(0, 200, 255); + textSize(250); + textAlign(CENTER); + text("Raindrop Game", width/2, height/5); + textSize(100); + text("Catch only WHITE raindrops in your bucket", width/2, height/4); + text("If you catch any other color, GAME OVER", width/2, height/3); + text("Press ENTER to start", width/2, height/2); + s=0; + t=0; + } + if (mode==1) { + mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + background(0, 200, 255); + r.add(new Raindrop(random(width), 0)); + c.bucket(mouseX, mouseY); + c.update(); + for (int i = r.size()-1; i>=0; i--) { + Raindrop d= r.get(i); + d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + d.display(); //display the raindrop + if (d.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + r.remove(i); //if it is, reset the raindrop + } + if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen + r.remove(i); //if it does, reset the raindrop + } + if (c.isInContactWith(d.loc)) { + r.remove(i); + if (d.y()) { + s+=1; + } + else { + mode = 3; + } + } + if (t = 100) { + mode = 2; + } } - if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen - r.remove(i); //if it does, reset the raindrop + textAlign(Center); + textSize(100); + fill(255); + text(s, width/2, height/10); + if (frameCount%10==0) { + t+=1; } + fill(255); + textSize(150); + text(t, width/2, height/9); + } + if (mode==2) { + background(0,200,255); + textAlign(CENTER); + textSize(200); + text("YOU WIN!", width/2, height/4); + textSize(150); + text("Final Score:", width/2-50, height/3); + text("s", width/2+50, height/3); + text("Press BACKSPACE to return to start screen", width/2, height/2); } -} \ No newline at end of file + if(mode==3) { + background(0,200,255); + textAlign(CENTER); + textSize(300); + text("YOU LOSE!!!", width/2, height/5); + textSize(150); + text("Final Score:", width/2-50, height/4); + text("s", width/2+50, height/4); + text("Final Time:", width/2-50, height/3); + text("t", width/2+50, height/3); + text("Press BACKSPACE to return to start screen", width/2, height/2); +} +} +void keyPressed() { + if (keyCode==ENTER) { //if player hits enter, enter main game sequence + mode=1; + } + if (keyCode==BACKSPACE) { //if player hits backspace, program shows opening page + mode=0; +} +} From d5e91980d88e0556b47555bca4dccc4ab9ff47be Mon Sep 17 00:00:00 2001 From: daena94 Date: Mon, 11 Jan 2016 13:24:54 -0500 Subject: [PATCH 6/9] kept working --- raindropGameCode/Bad.pde | 39 +++++++++++++++++++++++++++ raindropGameCode/Score.pde | 16 +++++++++++ raindropGameCode/raindropGameCode.pde | 25 ++++++++++++++--- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 raindropGameCode/Bad.pde create mode 100644 raindropGameCode/Score.pde diff --git a/raindropGameCode/Bad.pde b/raindropGameCode/Bad.pde new file mode 100644 index 0000000..75f45b1 --- /dev/null +++ b/raindropGameCode/Bad.pde @@ -0,0 +1,39 @@ +class Bad { + PVector loc, vel, a; + int r, diam; + + + + Bad() { + diam = 50; + loc = new PVector(random(diam, width-diam), 0); + vel = new PVector(0, random(1, 10)); + a = new PVector(0, 0.001); + } + + + void display() { + fill(0); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); + } + + void fall() { + loc.add(vel); + vel.add(a); + } + + boolean isInContactWith(Catcher c) { + if (c.loc.dist(loc) r = new ArrayList(); +ArrayList b = new ArrayList(); PVector circle; //declare a PVector called mouse Catcher c; - +Score s; +int mode = 0; void setup() { size(1200, 800); circle = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} r.add(new Raindrop(random(width), 0)); + b.add(new Bad(random(width), 0)); c = new Catcher(random(width), 0); + s = new Score(); } void draw() { + if(mode== 0){ + background(0); + textSize(30); + textAlign(CENTER); + text("Raindrop Game!", 600, 300); + text("Catch only the white raindrops. Press ENTER to begin.", width/2, height/2); + } + if(keyCode==ENTER){ + mode = 1; + } + if(mode == 1){ circle.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY background(0, 200, 255); r.add(new Raindrop(random(width), 0)); + b.add(new Bad(random(width), 0)); c.bucket(mouseX, mouseY); c.update(); + s.display(); for (int i = r.size()-1; i>=0; i--) { Raindrop d= r.get(i); d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity d.display(); //display the raindrop - if (d.isInContactWith(c.loc)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - r.remove(i); //if it is, reset the raindrop + if (d.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + r.remove(i); //if it is, reset the raindrop + s.addScore(); } if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen r.remove(i); //if it does, reset the raindrop } } + } } \ No newline at end of file From 858a2a90a76ef856591807b4452568de78004b83 Mon Sep 17 00:00:00 2001 From: daena94 Date: Wed, 13 Jan 2016 11:56:42 -0500 Subject: [PATCH 7/9] ALMOST DONE --- raindropGameCode/Bad.pde | 10 ++++--- raindropGameCode/Score.pde | 1 + raindropGameCode/raindropGameCode.pde | 38 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/raindropGameCode/Bad.pde b/raindropGameCode/Bad.pde index 75f45b1..ebb067a 100644 --- a/raindropGameCode/Bad.pde +++ b/raindropGameCode/Bad.pde @@ -4,7 +4,7 @@ class Bad { - Bad() { + Bad(float x, float y) { diam = 50; loc = new PVector(random(diam, width-diam), 0); vel = new PVector(0, random(1, 10)); @@ -25,9 +25,11 @@ class Bad { boolean isInContactWith(Catcher c) { if (c.loc.dist(loc)=1; i--) { + Bad bd= b.get(i); + bd.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + bd.display(); //display the raindrop + if (bd.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + b.remove(i); //if it is, reset the raindrop + mode = 3; + } + if (bd.loc.y > height + bd.diam/2) { //check to see if the raindrop goes below the bottom of the screen + b.remove(i); //if it does, reset the raindrop + } + } + } + if(mode == 3){ + background(0); + fill(0, 200, 255); + textAlign(CENTER); + textSize(40); + text("You Lose!!!",width/2,height/2); + text("Press DELETE to return to the start screen", width/2+50, height/2+50); + noLoop(); + + } + if(keyCode==DELETE){ + mode = 0; + } + //if(scoref == 50){ + //mode = 2; + //} + //if(mode == 2){ + // background(0); + //fill(0, 200, 255); + //textAlign(CENTER); + //textSize(40); + //text("You WIN!!!",width/2,height/2); + //text("Press BACKSPACE to return to the start screen", width/2+50, height/2+50); + //noLoop(); + //} } \ No newline at end of file From 1275795e25ae7b18e4544e00a92345e077cc599c Mon Sep 17 00:00:00 2001 From: daena94 Date: Fri, 15 Jan 2016 13:15:59 -0500 Subject: [PATCH 8/9] ALMOST DONE --- raindropGameCode/raindropGameCode.pde | 93 ++++++++++++++------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index ab3fd9b..53d6a91 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -15,63 +15,66 @@ void setup() { } void draw() { - if(mode== 0){ + if (mode == 0) { background(0); textSize(30); textAlign(CENTER); text("Raindrop Game!", 600, 300); text("Catch only the white raindrops. Press ENTER to begin.", width/2, height/2); } - if(keyCode==ENTER){ + if (keyCode==ENTER) { mode = 1; } - if(mode == 1){ - circle.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - background(0, 200, 255); - r.add(new Raindrop(random(width), 0)); - b.add(new Bad(random(width), 0)); - c.bucket(mouseX, mouseY); - c.update(); - s.display(); - for (int i = r.size()-1; i>=0; i--) { - Raindrop d= r.get(i); - d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - d.display(); //display the raindrop - if (d.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - r.remove(i); //if it is, reset the raindrop - s.addScore(); - } - if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen - r.remove(i); //if it does, reset the raindrop + if (mode == 1) { + circle.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + background(0, 200, 255); + r.add(new Raindrop(random(width), 0)); + b.add(new Bad(random(width), 0)); + c.bucket(mouseX, mouseY); + c.update(); + s.display(); + for (int i = r.size()-1; i>=0; i--) { + Raindrop d= r.get(i); + d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + d.display(); //display the raindrop + if (d.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + r.remove(i); //if it is, reset the raindrop + s.addScore(); + } + if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen + r.remove(i); //if it does, reset the raindrop + } } - } - for (int i = b.size()-1; i>=1; i--) { - Bad bd= b.get(i); - bd.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - bd.display(); //display the raindrop - if (bd.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - b.remove(i); //if it is, reset the raindrop - mode = 3; + + for (int i = b.size()-1; i>=1; i--) { + if(b.size()<200){ + Bad bd= b.get(i); + + bd.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + bd.display(); //display the raindrop + if (bd.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + b.remove(i); //if it is, reset the raindrop + mode = 2; + } + if (bd.loc.y > height + bd.diam/2) { //check to see if the raindrop goes below the bottom of the screen + b.remove(i); //if it does, reset the raindrop + } } - if (bd.loc.y > height + bd.diam/2) { //check to see if the raindrop goes below the bottom of the screen - b.remove(i); //if it does, reset the raindrop + + if (mode == 2) { + background(0); + fill(0, 200, 255); + textAlign(CENTER); + textSize(40); + text("You Lose!!!", width/2, height/2); + text("Press DELETE to return to the start screen", width/2+50, height/2+50); + noLoop(); + if (key==1) { + mode = 0; + } } } - } - if(mode == 3){ - background(0); - fill(0, 200, 255); - textAlign(CENTER); - textSize(40); - text("You Lose!!!",width/2,height/2); - text("Press DELETE to return to the start screen", width/2+50, height/2+50); - noLoop(); - - } - if(keyCode==DELETE){ - mode = 0; - - } + //if(scoref == 50){ //mode = 2; //} From 2cd40f3340b9d3862156223d882aa74ca2187819 Mon Sep 17 00:00:00 2001 From: daena94 Date: Sun, 17 Jan 2016 15:41:32 -0500 Subject: [PATCH 9/9] finished kind of --- raindropGameCode/Bad.pde | 42 ++--- raindropGameCode/Catcher.pde | 26 +-- raindropGameCode/Raindrop.pde | 78 +++------ raindropGameCode/Score.pde | 16 +- raindropGameCode/raindropGameCode.pde | 235 ++++++++------------------ 5 files changed, 135 insertions(+), 262 deletions(-) diff --git a/raindropGameCode/Bad.pde b/raindropGameCode/Bad.pde index ebb067a..c27c2f5 100644 --- a/raindropGameCode/Bad.pde +++ b/raindropGameCode/Bad.pde @@ -1,41 +1,41 @@ -class Bad { - PVector loc, vel, a; - int r, diam; +class Bad { //new class called Bad + PVector loc, vel, a; //new PVectors loc, vel, a + int r, diam; //initialize variables r, diam - Bad(float x, float y) { - diam = 50; - loc = new PVector(random(diam, width-diam), 0); - vel = new PVector(0, random(1, 10)); - a = new PVector(0, 0.001); + Bad(float x, float y) { //float coordinates of Bad + diam = 50; //diam equals 50 + loc = new PVector(random(diam, width-diam), 0); //initialize loc PVector + vel = new PVector(0, random(1, 10)); //initialize vel PVector + a = new PVector(0, 0.001); //initialize a PVector } void display() { - fill(0); - noStroke(); - ellipse(loc.x, loc.y, diam, diam); + fill(0); //set fill to black + noStroke(); //no stroke + ellipse(loc.x, loc.y, diam, diam); //draw ellipse for raindrops } void fall() { - loc.add(vel); - vel.add(a); + loc.add(vel); //add velocity to the Bad raindrop + vel.add(a); //add acceleration to the velocity } - boolean isInContactWith(Catcher c) { - if (c.loc.dist(loc).25 && ran<.5) { - a=b; - } - if (ran>.5 && ran<.75) { - a=c; - } - if (ran>.75) { - a=d; - } - } - - boolean y() { - if (a==a) { - return true; - } - else { - return false; - } + loc.x = random(width); //choose a random x-value for the raindrop + loc.y = 0; //set the y-value to 0 } } - diff --git a/raindropGameCode/Score.pde b/raindropGameCode/Score.pde index 4d041da..e3aea1d 100644 --- a/raindropGameCode/Score.pde +++ b/raindropGameCode/Score.pde @@ -1,17 +1,17 @@ -class Score { - int scoref = 0; +class Score { //new class called Score + int scoref = 0; //variable scoref equals 0 Score() { - textSize(50); + textSize(50); //set text size to 50 } void display() { - textSize(50); - text("Score", 70, 50); - text(scoref, 200, 50); + textSize(50); //set text size to 50 + text("Score", 70, 50); //insert text + text(scoref, 200, 50); //insert text } void addScore() { - scoref ++ ; + scoref ++ ; //increase score } -} \ No newline at end of file +} diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index b3d631a..9c65881 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,187 +1,94 @@ -ArrayList r = new ArrayList(); - -PVector mouse; //declare a PVector called mouse -Catcher c; -int count = 10; -int mode = 0; -int t = 0; -int s = 0; - -ArrayList b = new ArrayList(); -PVector circle; //declare a PVector called mouse -Catcher c; -Score s; -int mode = 0; - +ArrayList r = new ArrayList(); //declare an Array List for the good raindrop +ArrayList b = new ArrayList(); //declare an Array List for the bad raindrop +PVector circle; //declare a PVector called circle +Catcher c; //declare c as a variable for the Catcher class +Score s; //declare s as a variable for the Score class +int mode = 0; //initialize variable mode 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(random(width), 0)); - - c = new Catcher(width/2, height/2); -} - -void draw() { - if (mode==0) { - background(0, 200, 255); - textSize(250); - textAlign(CENTER); - text("Raindrop Game", width/2, height/5); - textSize(100); - text("Catch only WHITE raindrops in your bucket", width/2, height/4); - text("If you catch any other color, GAME OVER", width/2, height/3); - text("Press ENTER to start", width/2, height/2); - s=0; - t=0; - } - if (mode==1) { - mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - background(0, 200, 255); - r.add(new Raindrop(random(width), 0)); - c.bucket(mouseX, mouseY); - c.update(); - - b.add(new Bad(random(width), 0)); - c = new Catcher(random(width), 0); - s = new Score(); + size(1200, 800); //set canvas size + circle = new PVector(); //initialize circle PVector. value is irrelevant since it will be set at the start of void draw(){} + r.add(new Raindrop(random(width), 0)); //add new Raindrop + b.add(new Bad(random(width), 0)); //add new Bad raindrop + c = new Catcher(random(width), 0); //add new Catcher + s = new Score(); //add new Score } void draw() { - if (mode == 0) { - background(0); - textSize(30); - textAlign(CENTER); - text("Raindrop Game!", 600, 300); - text("Catch only the white raindrops. Press ENTER to begin.", width/2, height/2); + if (mode == 0) { //if the mode is set to 0... + background(0); //set background to black + textSize(30); //set text size to 30 + textAlign(CENTER); //align the text to the center of the screen + text("Raindrop Game!", 600, 300); //insert text + text("Catch only the white raindrops. Press ENTER to begin.", width/2, height/2); //insert text } - if (keyCode==ENTER) { - mode = 1; + if (keyCode==ENTER) { //if the ENTER key is pressed... + mode = 1; //set the mode to 1 } - if (mode == 1) { - circle.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - background(0, 200, 255); - r.add(new Raindrop(random(width), 0)); - b.add(new Bad(random(width), 0)); - c.bucket(mouseX, mouseY); - c.update(); - s.display(); - - for (int i = r.size()-1; i>=0; i--) { - Raindrop d= r.get(i); + if (mode == 1) { //if the mode is set to 1... + circle.set(mouseX, mouseY); //set value of circle as mouseX,mouseY + background(0, 200, 255); //set the background color + r.add(new Raindrop(random(width), 0)); //add new Raindrop + b.add(new Bad(random(width), 0)); //add new Bad raindrop + c.bucket(mouseX, mouseY); //catcher bucket + c.update(); //update the catcher + s.display(); //display the score + for (int i = r.size()-1; i>=0; i--) { //keep making new raindrops + Raindrop d= r.get(i); //add Raindrop d d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity d.display(); //display the raindrop - if (d.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - - r.remove(i); //if it is, reset the raindrop - - r.remove(i); //if it is, reset the raindrop - s.addScore(); - + if (d.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the Catcher + r.remove(i); //if it is, remove the raindrop + s.addScore(); //increase the score } if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen - r.remove(i); //if it does, reset the raindrop + r.remove(i); //if it does, remove the raindrop } + } - if (c.isInContactWith(d.loc)) { - r.remove(i); - if (d.y()) { - s+=1; + for (int i = b.size()-1; i>=1; i--) { //keep makng new bad raindrops + if (b.size()<200) { //if there are less than 200 bad raindrops on the screen... + Bad bd= b.get(i); //add new bad raindrops + + bd.fall(); //make the bad raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + bd.display(); //display the bad raindrop + if (bd.isInContactWith(c)) { //check to see if the bad raindrop is in contact with the point represented by the Catcher + b.remove(i); //if it is, remove the bad raindrop + mode = 2; //set the mode to 2 } - else { - mode = 3; + if (bd.loc.y > height + bd.diam/2) { //check to see if the bad raindrop goes below the bottom of the screen + b.remove(i); //if it does, remove the bad raindrop } } - if (t = 100) { - mode = 2; - } - } - textAlign(Center); - textSize(100); - fill(255); - text(s, width/2, height/10); - if (frameCount%10==0) { - t+=1; - } - - for (int i = b.size()-1; i>=1; i--) { - if(b.size()<200){ - Bad bd= b.get(i); - - bd.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - bd.display(); //display the raindrop - if (bd.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - b.remove(i); //if it is, reset the raindrop - mode = 2; - } - if (bd.loc.y > height + bd.diam/2) { //check to see if the raindrop goes below the bottom of the screen - b.remove(i); //if it does, reset the raindrop + if (mode == 2) { //if the mode is set to 2... + background(0); //set the background to black + fill(0, 200, 255); //set the color of the text + textAlign(CENTER); //align the text to the center of the screen + textSize(40); //set the text size to 40 + text("You Lose!!!", width/2, height/2); //insert text + text("Press DELETE to return to the start screen", width/2+50, height/2+50); //insert text + noLoop(); //do not loop + if (key==DELETE) { //if the DELETE key is pressed... + mode = 0; //set the mode to 0 + } } - } - if (mode == 2) { - background(0); - fill(0, 200, 255); - textAlign(CENTER); - textSize(40); - text("You Lose!!!", width/2, height/2); - text("Press DELETE to return to the start screen", width/2+50, height/2+50); - noLoop(); - if (key==1) { - mode = 0; - } + if (scoref == 50) { //if the score reaches 50... + mode = 3; //set the mode to 3 + } + if (mode == 3) { //if the mode is set to 3... + background(0); //set the background to black + fill(0, 200, 255); //set the color of the text + textAlign(CENTER); //align the text to the center of the screen + textSize(40); //set the text size to 40 + text("You WIN!!!", width/2, height/2); //insert text + text("Press BACKSPACE to return to the start screen", width/2+50, height/2+50); //insert text + noLoop(); //do not loop + } + if(keyCode == BACKSPACE) { //if the BACKSPACE key is pressed... + mode = 0; //set the mode to 0 } - fill(255); - textSize(150); - text(t, width/2, height/9); - } - if (mode==2) { - background(0,200,255); - textAlign(CENTER); - textSize(200); - text("YOU WIN!", width/2, height/4); - textSize(150); - text("Final Score:", width/2-50, height/3); - text("s", width/2+50, height/3); - text("Press BACKSPACE to return to start screen", width/2, height/2); } - if(mode==3) { - background(0,200,255); - textAlign(CENTER); - textSize(300); - text("YOU LOSE!!!", width/2, height/5); - textSize(150); - text("Final Score:", width/2-50, height/4); - text("s", width/2+50, height/4); - text("Final Time:", width/2-50, height/3); - text("t", width/2+50, height/3); - text("Press BACKSPACE to return to start screen", width/2, height/2); -} -} -void keyPressed() { - if (keyCode==ENTER) { //if player hits enter, enter main game sequence - mode=1; - } - if (keyCode==BACKSPACE) { //if player hits backspace, program shows opening page - mode=0; -} -} - - - //if(scoref == 50){ - //mode = 2; - //} - //if(mode == 2){ - // background(0); - //fill(0, 200, 255); - //textAlign(CENTER); - //textSize(40); - //text("You WIN!!!",width/2,height/2); - //text("Press BACKSPACE to return to the start screen", width/2+50, height/2+50); - //noLoop(); - //} -} -