Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions raindropGameCode/catcher_class.pde
Original file line number Diff line number Diff line change
@@ -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);
}
}
Binary file added raindropGameCode/data/beach.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raindropGameCode/data/trash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 63 additions & 10 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,79 @@
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<Raindrop> drops = new ArrayList<Raindrop>(); //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
// You can start out by just using the single Raindrop as you test


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);
}
39 changes: 39 additions & 0 deletions raindropGameCode/raindrop_class.pde
Original file line number Diff line number Diff line change
@@ -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;
}
}