From 2c4c4fc81a72562473a76206644ff096bfc6316c Mon Sep 17 00:00:00 2001 From: allwhen Date: Tue, 15 Dec 2015 08:30:24 -0500 Subject: [PATCH 1/8] working class and code --- raindropGameCode/Raindrop.pde | 36 +++++++++++++++++++++++++++ raindropGameCode/raindropGameCode.pde | 8 +++--- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 raindropGameCode/Raindrop.pde diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde new file mode 100644 index 0000000..ab674fb --- /dev/null +++ b/raindropGameCode/Raindrop.pde @@ -0,0 +1,36 @@ +class Raindrop { + PVector pos = new PVector(); + PVector vel = new PVector(); + PVector acc = new PVector(); + float diam; + Raindrop() { + pos.x = random(width); pos.y = random(height); + vel.x = 0; vel.y = 0; + acc.x = 0; acc.y = .2; + diam = 30; + } + + Raindrop(float x, float y) { + pos.x = x; pos.y = y; + vel.x = 0; vel.y = 0; + acc.x = 0; acc.y = .2; + diam = 30; + } + + void fall() { + pos.add(vel); + vel.add(acc); + } + void display() { + ellipse(pos.x,pos.y,diam,diam); + } + void reset() { + vel.y = 0; + pos.y = 0; + } + + boolean touches(PVector a) { + a.sub(pos); + return a.mag()<=diam; + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..231433b 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -14,13 +14,13 @@ void setup() { void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - background(0, 200, 255); + background(0, 100, 200); 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 + if (r.touches(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.loc.y > height + r.diam/2) { //check to see if the raindrop goes below the bottom of the screen + if (r.pos.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 d82223d55f08d91eb4e29969d9578fe3f5750c8b Mon Sep 17 00:00:00 2001 From: allwhen Date: Tue, 15 Dec 2015 09:23:37 -0500 Subject: [PATCH 2/8] addition of scoring and arrays --- raindropGameCode/Raindrop.pde | 29 ++++++++++++++--------- raindropGameCode/raindropGameCode.pde | 33 ++++++++++++++++++--------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index ab674fb..a4b8073 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -3,34 +3,41 @@ class Raindrop { PVector vel = new PVector(); PVector acc = new PVector(); float diam; + + //initializer (empty) Raindrop() { - pos.x = random(width); pos.y = random(height); - vel.x = 0; vel.y = 0; - acc.x = 0; acc.y = .2; + pos.set(random(width), random(height)); + vel.set(0, 0); + acc.set(0, .2); diam = 30; } - + + //initializes at a point Raindrop(float x, float y) { - pos.x = x; pos.y = y; - vel.x = 0; vel.y = 0; - acc.x = 0; acc.y = .2; + pos.set(x, y); + vel.set(0, 0); + acc.set(0, .2); diam = 30; } + //moves raindrop, accelerates void fall() { pos.add(vel); vel.add(acc); } + + //draws raindrop void display() { - ellipse(pos.x,pos.y,diam,diam); + ellipse(pos.x, pos.y, diam, diam); } + + //moves raindrop back to the top void reset() { vel.y = 0; - pos.y = 0; + pos.set(random(width),0); } boolean touches(PVector a) { - a.sub(pos); - return a.mag()<=diam; + return a.dist(pos)<=diam/2; } } \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 231433b..1e6274d 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,37 @@ PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r +int num = 100; //#raindrops +int score = 0; //number of raindrops touched +Raindrop[] r = new Raindrop[num]; // 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 = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions + 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 + background(200, 200, 255); + for (int j=0; j height + r[j].diam/2) { //check to see if the raindrop goes below the bottom of the screen + r[j].reset(); //if it does, reset the raindrop + } } + text(score,width/2,40); } \ No newline at end of file From e011ee52e8fa68f19a85160ba14f4cd5d8ecbfc6 Mon Sep 17 00:00:00 2001 From: allwhen Date: Mon, 21 Dec 2015 08:48:14 -0500 Subject: [PATCH 3/8] ketcher class --- raindropGameCode/Catcher.pde | 17 +++++++++++++++++ raindropGameCode/Raindrop.pde | 4 ++++ raindropGameCode/raindropGameCode.pde | 1 + 3 files changed, 22 insertions(+) create mode 100644 raindropGameCode/Catcher.pde diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde new file mode 100644 index 0000000..018b3e7 --- /dev/null +++ b/raindropGameCode/Catcher.pde @@ -0,0 +1,17 @@ +class Catcher { + float diam; + PVector pos = new PVector(); + + Catcher(float tDiam) { + pos.set(mouseX,mouseY); + diam = tDiam; + } + + void display() { + ellipse(pos.x,pos.y,diam,diam); + } + + void update() { + pos.set(mouseX,mouseY); + } +} \ No newline at end of file diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index a4b8073..dd80681 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -40,4 +40,8 @@ class Raindrop { boolean touches(PVector a) { return a.dist(pos)<=diam/2; } + + boolean touches(Catcher a) { + return a.pos.dist(pos)<=diam/2+a.diam/2; + } } \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 1e6274d..a784e25 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -2,6 +2,7 @@ PVector mouse; //declare a P int num = 100; //#raindrops int score = 0; //number of raindrops touched Raindrop[] r = new Raindrop[num]; +ArrayList drops = new ArrayList(); // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object From 96cec03d50ced6704cc0b14b12ea24dc8735f35f Mon Sep 17 00:00:00 2001 From: allwhen Date: Mon, 21 Dec 2015 08:57:44 -0500 Subject: [PATCH 4/8] better catcher, no more mouse PVector --- raindropGameCode/Catcher.pde | 3 +++ raindropGameCode/Raindrop.pde | 1 + raindropGameCode/raindropGameCode.pde | 9 ++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde index 018b3e7..333a8b7 100644 --- a/raindropGameCode/Catcher.pde +++ b/raindropGameCode/Catcher.pde @@ -1,13 +1,16 @@ class Catcher { float diam; PVector pos = new PVector(); + color c; Catcher(float tDiam) { pos.set(mouseX,mouseY); diam = tDiam; + c = color(random(255),random(255),random(255)); } void display() { + fill(c); ellipse(pos.x,pos.y,diam,diam); } diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index dd80681..bfb537e 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -28,6 +28,7 @@ class Raindrop { //draws raindrop void display() { + fill(0, 0, 255); ellipse(pos.x, pos.y, diam, diam); } diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index a784e25..6cb0a2b 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -4,6 +4,9 @@ int score = 0; //number of raindrops touched Raindrop[] r = new Raindrop[num]; ArrayList drops = new ArrayList(); +Catcher catcher = new Catcher(200); + + // 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,18 +18,17 @@ void setup() { r[i] = new Raindrop(random(width), random(height)); //Initialize r. The parameters used are the initial x and y positions } noStroke(); - fill(0, 0, 255); textSize(40); textAlign(CENTER); } void draw() { - mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY background(200, 200, 255); + catcher.display(); for (int j=0; j Date: Mon, 21 Dec 2015 09:05:07 -0500 Subject: [PATCH 5/8] creation of thing for raindrops --- raindropGameCode/raindropGameCode.pde | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 6cb0a2b..387bf62 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -2,7 +2,7 @@ PVector mouse; //declare a P int num = 100; //#raindrops int score = 0; //number of raindrops touched Raindrop[] r = new Raindrop[num]; -ArrayList drops = new ArrayList(); +ArrayList drops = new ArrayList(); Catcher catcher = new Catcher(200); @@ -25,7 +25,13 @@ void setup() { void draw() { background(200, 200, 255); catcher.display(); - for (int j=0; j=0; j--) { + + } + + /*for (int j=0; j Date: Tue, 5 Jan 2016 09:11:36 -0500 Subject: [PATCH 6/8] uses arraylist, bucket grows upon "eating" --- raindropGameCode/Raindrop.pde | 4 +-- raindropGameCode/raindropGameCode.pde | 46 +++++++++++---------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index bfb537e..1ac45f7 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -9,7 +9,7 @@ class Raindrop { pos.set(random(width), random(height)); vel.set(0, 0); acc.set(0, .2); - diam = 30; + diam = random(20,45); } //initializes at a point @@ -17,7 +17,7 @@ class Raindrop { pos.set(x, y); vel.set(0, 0); acc.set(0, .2); - diam = 30; + diam = random(20,45); } //moves raindrop, accelerates diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 387bf62..9f978fa 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,48 +1,38 @@ -PVector mouse; //declare a P -int num = 100; //#raindrops int score = 0; //number of raindrops touched -Raindrop[] r = new Raindrop[num]; ArrayList drops = new ArrayList(); +boolean flag = false; -Catcher catcher = new Catcher(200); - - -// 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 bucket = new Catcher(50); 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(){} - for (int i=0; i=0; j--) { - - } - - /*for (int j=0; j height + r[j].diam/2) { //check to see if the raindrop goes below the bottom of the screen - r[j].reset(); //if it does, reset the raindrop + else if (rain.pos.y > height + rain.diam/2) { + drops.remove(j); } } - */ - catcher.update(); - text(score,width/2,40); + + bucket.update(); + fill(100,150,255); + text(bucket.diam/2,width/2,40); } \ No newline at end of file From 6490bbe37e5949bb546293b9a405a1a0811e4533 Mon Sep 17 00:00:00 2001 From: allwhen Date: Tue, 5 Jan 2016 09:18:25 -0500 Subject: [PATCH 7/8] better commenting, display an integer radius --- raindropGameCode/Catcher.pde | 9 ++++++--- raindropGameCode/Raindrop.pde | 4 +++- raindropGameCode/raindropGameCode.pde | 10 +++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde index 333a8b7..ea62594 100644 --- a/raindropGameCode/Catcher.pde +++ b/raindropGameCode/Catcher.pde @@ -1,19 +1,22 @@ class Catcher { - float diam; - PVector pos = new PVector(); - color c; + float diam; //diameter + PVector pos = new PVector(); //position + color c; //color + //catcher with diameter from parameter Catcher(float tDiam) { pos.set(mouseX,mouseY); diam = tDiam; c = color(random(255),random(255),random(255)); } + //circle at position with color and diameter desired. void display() { fill(c); ellipse(pos.x,pos.y,diam,diam); } + //updates catcher's position void update() { pos.set(mouseX,mouseY); } diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde index 1ac45f7..9ef6bec 100644 --- a/raindropGameCode/Raindrop.pde +++ b/raindropGameCode/Raindrop.pde @@ -32,16 +32,18 @@ class Raindrop { ellipse(pos.x, pos.y, diam, diam); } - //moves raindrop back to the top + //moves raindrop back to the top (not used) void reset() { vel.y = 0; pos.set(random(width),0); } + //returns whether or not the raindrop touches some point boolean touches(PVector a) { return a.dist(pos)<=diam/2; } + //returns whether or not raindrop touches a catcher boolean touches(Catcher a) { return a.pos.dist(pos)<=diam/2+a.diam/2; } diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 9f978fa..6ad1902 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -18,21 +18,25 @@ void draw() { drops.add(new Raindrop(random(width),0)); + //goes through arraylist for(int j = drops.size()-1; j>=0; j--) { Raindrop rain = drops.get(j); rain.fall(); rain.display(); + if (rain.touches(bucket)) { drops.remove(j); score++; - bucket.diam+=rain.diam/100; + bucket.diam+=rain.diam/100; //increase bucket's size, remove drop } else if (rain.pos.y > height + rain.diam/2) { - drops.remove(j); + drops.remove(j); //drops disappear when falling off screen } } bucket.update(); + fill(100,150,255); - text(bucket.diam/2,width/2,40); + + text(round(bucket.diam/2),width/2,40); //shows size of bucket } \ No newline at end of file From b1d9b6bfcb56d996f2eace219967e622f51d9532 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 6 Jan 2016 22:33:59 -0500 Subject: [PATCH 8/8] window dressing, to feel like a game --- raindropGameCode/raindropGameCode.pde | 76 ++++++++++++++++++--------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 6ad1902..129a3d9 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,6 +1,7 @@ int score = 0; //number of raindrops touched ArrayList drops = new ArrayList(); -boolean flag = false; +boolean pause = true; +boolean start = false; Catcher bucket = new Catcher(50); @@ -10,33 +11,60 @@ void setup() { noCursor(); textSize(40); textAlign(CENTER); + background(0); } void draw() { - background(200, 200, 255); - bucket.display(); - - drops.add(new Raindrop(random(width),0)); - - //goes through arraylist - for(int j = drops.size()-1; j>=0; j--) { - Raindrop rain = drops.get(j); - rain.fall(); - rain.display(); - - if (rain.touches(bucket)) { - drops.remove(j); - score++; - bucket.diam+=rain.diam/100; //increase bucket's size, remove drop + if (bucket.diam/2<720) { //if victory conditions have not been satisfied + if (!pause) { //if game hasn't been paused + noCursor(); + background(200, 200, 255); + bucket.display(); + + drops.add(new Raindrop(random(width), 0)); + + //goes through arraylist + for (int j = drops.size()-1; j>=0; j--) { + Raindrop rain = drops.get(j); + rain.fall(); + rain.display(); + + if (rain.touches(bucket)) { + drops.remove(j); + score++; + bucket.diam+=rain.diam/100; //increase bucket's size, remove drop + } else if (rain.pos.y > height + rain.diam/2) { + drops.remove(j); //drops disappear when falling off screen + } + } + + bucket.update(); + + fill(100, 150, 255); + + text(round(bucket.diam/2), width/2, 40); //shows size of bucket + } else { + cursor(); + if (start) { + text("pause", width/2, height/2); + } } - else if (rain.pos.y > height + rain.diam/2) { - drops.remove(j); //drops disappear when falling off screen + + if (!start) { //starting screen + text("click to toggle pause", width/2, height/2); + text("mouse to move", width/2, height/2-50); + text("consume raindrops until you can swallow the screen", width/2, height/2-200); } } + else { //victory screen + background(255); + fill(0); + text("All will become one. Devour.",width/2,height/2); + } +} + +void mouseClicked() { //start game, pause game. + pause = !pause; + start = true; +} - bucket.update(); - - fill(100,150,255); - - text(round(bucket.diam/2),width/2,40); //shows size of bucket -} \ No newline at end of file