diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde new file mode 100644 index 0000000..ea62594 --- /dev/null +++ b/raindropGameCode/Catcher.pde @@ -0,0 +1,23 @@ +class Catcher { + 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); + } +} \ No newline at end of file diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde new file mode 100644 index 0000000..9ef6bec --- /dev/null +++ b/raindropGameCode/Raindrop.pde @@ -0,0 +1,50 @@ +class Raindrop { + PVector pos = new PVector(); + PVector vel = new PVector(); + PVector acc = new PVector(); + float diam; + + //initializer (empty) + Raindrop() { + pos.set(random(width), random(height)); + vel.set(0, 0); + acc.set(0, .2); + diam = random(20,45); + } + + //initializes at a point + Raindrop(float x, float y) { + pos.set(x, y); + vel.set(0, 0); + acc.set(0, .2); + diam = random(20,45); + } + + //moves raindrop, accelerates + void fall() { + pos.add(vel); + vel.add(acc); + } + + //draws raindrop + void display() { + fill(0, 0, 255); + ellipse(pos.x, pos.y, diam, diam); + } + + //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; + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..129a3d9 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,70 @@ -PVector mouse; //declare a P -Raindrop r; //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 -// You can start out by just using the single Raindrop as you test +int score = 0; //number of raindrops touched +ArrayList drops = new ArrayList(); +boolean pause = true; +boolean start = false; +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(){} - r = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions + noStroke(); + noCursor(); + textSize(40); + textAlign(CENTER); + background(0); } 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 + 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); + } + } + + 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); + } } - 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 + 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; +} +