diff --git a/raindropGameCode/catcher_class.pde b/raindropGameCode/catcher_class.pde new file mode 100644 index 0000000..4e17731 --- /dev/null +++ b/raindropGameCode/catcher_class.pde @@ -0,0 +1,17 @@ +class Catcher { //create catcher class + int diam; + PVector loc; + + Catcher(int tDiam) { + loc = new PVector(mouseX, mouseY); + diam= tDiam; + } + + void display() { //display function to use w/in catcher class + fill(178, 175, 214); + ellipse(loc.x, loc.y, diam, diam); + } + void update() { //update function to use w/in catcher class + loc.set(mouseX, mouseY); + } +} \ No newline at end of file diff --git a/raindropGameCode/data/beach.jpg b/raindropGameCode/data/beach.jpg new file mode 100644 index 0000000..0dafb79 Binary files /dev/null and b/raindropGameCode/data/beach.jpg differ diff --git a/raindropGameCode/data/trash.jpg b/raindropGameCode/data/trash.jpg new file mode 100644 index 0000000..0233f0e Binary files /dev/null and b/raindropGameCode/data/trash.jpg differ diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..71527a7 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,5 +1,12 @@ +PImage beach; //image for background PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r +int count = 100; +//Raindrop [] r = new Raindrop[count]; //declare a new Raindrop called r +ArrayList drops = new ArrayList(); //declare & initialize Array list +Catcher c; +int score; +float start; + // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object @@ -7,20 +14,66 @@ Raindrop r; //declare a new Raindrop called r void setup() { + start = 1; 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 + c= new Catcher(100); //initialize catcher + beach = loadImage ("beach.jpg"); //load background image + +} + + +void draw() { //function for startscreen + if (start==1) { + background(207, 87, 110); + textSize(40); + text("Clean Up the Beach!", width/2, 200); + text("Click the Mouse to Start", width/2-100, 300); + if (mousePressed == true) { // if the mouse is pressed + start = 2; + } + } + if (start == 2) { //the game starts + game(); + } } -void draw() { + +void game() { //function for game + + textSize(32); //text size + text("Clean the Beach", width/2, height/2); 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 + background(63, 83, 87); + image(beach, 0, 0); + + drops.add(new Raindrop(random(width), 0)); // + + for (int i = drops.size()-1; i >= 0; i--) { + Raindrop r = drops.get(i); + 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(c)) { //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 + score+=1; // add 1 to score + } } - 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 + c.display(); //display the catcher + c.update(); + textSize(32); + fill(0); + text(score, width/2, 700); + if (score > 150) { //when score is more than 100 + gamedone(); // //go to gamedone functions } } + +void gamedone() { //gamedone function, game over screen + background (0); + textSize(45); + fill(255); + text("You failed to clean up the beach.", 50, height/2); +} \ No newline at end of file diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde new file mode 100644 index 0000000..46eba36 --- /dev/null +++ b/raindropGameCode/raindrop_class.pde @@ -0,0 +1,39 @@ +class Raindrop { //create raindrop class + PVector loc, vel, acc; + float diam; + PImage trash; + + Raindrop(float x, float y) { + loc = new PVector(x, y); + vel =new PVector(random(0, 2), random(0, 2)); + acc= new PVector(0.0001, .00002); + diam = 30; + trash = loadImage("trash.jpg"); + } + + void display() { + image(trash, loc.x, loc.y); + + } + + void fall() { + loc.y = loc.y + vel.y; + vel.add(acc); + } + + void reset() { + loc.y = 0; + vel.set(0, 9); + } + + boolean isInContactWith(Catcher bucket) { + float d = loc.dist(bucket.loc); + boolean e; + if (d< diam/2+ bucket.diam) { + e = true ; + } else { + e = false; + } + return e; + } +} \ No newline at end of file