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
20 changes: 20 additions & 0 deletions raindropGameCode/catcher.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Catcher{
PVector loc;
int diam;

Catcher(int tdiam){
loc = new PVector();
diam = tdiam;
}

void display(){
fill(0);
ellipse(loc.x,loc.y,diam,diam);
}

void update(){
loc.set(mouseX,mouseY);
}

}

33 changes: 33 additions & 0 deletions raindropGameCode/raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Raindrop {// declaring all fields contained within Raindrop Class
PVector loc, vel, acc; //declare variables and PVectors and intergers
int diam;
Raindrop(float x, float y) {
diam = 30;
loc= new PVector(x, y);
vel = new PVector(random(-3, 3), random(-3, 3));
acc = new PVector(0, .01);
}
void display() {
fill(253);
noStroke();
ellipse(loc.x, loc.y, diam, diam);
}
void fall() {
loc.y=loc.y + vel.y; // add velocity to create fall
vel.add(acc); //add gravity to the game
}
void reset() {
loc.y=0;
vel.set(0,10);
}
boolean isInContactWith(PVector mouse) { //get rid of the rain
float d = dist(loc.x, loc.y, mouse.x, mouse.y); //determine if the mouse is within the circle/in contact
boolean c;
if ( d < diam/2) {
c = true;
} else {
c =false;
}
return c;
}
}
49 changes: 35 additions & 14 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
int count=100;
PVector mouse; //declare a P
Raindrop r; //declare a new Raindrop called r

ArrayList <Raindrop> raindrops = new ArrayList();
//Raindrop[] r = new Raindrop[count]; //declare a new Raindrop called r
Catcher c;
// 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
}

mouse = new PVector();
c = new Catcher(50);
raindrops.add(new Raindrop(mouseX,mouseY));
//for(int i = 0; i <count; i++){//initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){}
// r[i] = new Raindrop(random(width), 0);
}//Initialize r. The parameters used are the initial x and y positions


void draw() {
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
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 (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
raindrops.add(new Raindrop(random(width),0));
c.update();
c.display();
for(int i = raindrops.size()-1; i >= 0; i--){
Raindrop r = raindrops.get(i);
r.display();
r.fall();
if(r.isInContactWith(mouse)){
raindrops.remove(i);
}
}
}
//for(int i = 0; i < count; i++){
//r[i].fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity
//r[i].display();
////display the raindrop
//if (r[i].isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse
// r[i].reset(); //if it is, reset the raindrop
//}
//if (r[i].loc.y > height + r[i].diam/2) { //check to see if the raindrop goes below the bottom of the screen
// r[i].reset(); //if it does, reset the raindrop
//}
//}
}