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
61 changes: 61 additions & 0 deletions raindropGameCode/Raindropclass.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class Blooddrop { //declare a class for the blood
PVector loc; //declare pvector for location
PVector vel; //declare pvector for velocity
float diam, locx, locy, grav; //declare diameter, x location, y location, and gravity

Blooddrop(float locx, float locy) { //make a blooddrop at the location the user chooses
loc = new PVector(locx, locy); //make the location be
vel = new PVector(0, 1); //velocity
diam = 25; //diameter of the blooddrop is 25
grav = 0.0981; //gravity of the blooddrop is actual gravity
}
void fall() {
loc.add(vel);
vel.y += grav;
}
void display() {
noStroke();
fill(200,0,0);
ellipse(loc.x, loc.y, 2*diam/3, diam);
}
void reset() {
loc.x = random(width);
loc.y = 0;
vel.y = 1;
}
boolean isInContactWith(PVector thing) {
if (loc.dist(thing)<diam/2) {
return true;
} else {
return false;
}
}
}

class catcher {
PVector loc;
int w,h;

catcher() {
loc = new PVector();
w = 100;
h= 20;
}
void display() {
rectMode(CENTER);
fill(255);
rect(loc.x, loc.y, w, h);
}
void update(){
loc.set(mouseX, mouseY);
}
boolean isCatching(Blooddrop droplet){
if (droplet.loc.x + droplet.diam/2 > loc.x - w/2 && droplet.loc.x - droplet.diam/2 < loc.x + w/2 && droplet.loc.y + droplet.diam/2 > loc.y - h/2 && droplet.loc.y - droplet.diam/2 < loc.y + h/2) {
return true;
}else{
return false;
}
}


}
66 changes: 50 additions & 16 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,60 @@
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

Blooddrop r; //declare a new Raindrop called r
catcher tissue;
ArrayList<Blooddrop> blooddrops = new ArrayList<Blooddrop>(); //declare and initialize the ArrayList
int startingBlood = 2;

void setup() {
size(1200, 800);
size(800, 600);
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
blooddrops.add(new Blooddrop(width/2, mouseY)); //add a new raindrop to the raindrop ArrayList
tissue = new catcher();

for (int i = 0; i < startingBlood; i++) {

blooddrops.add(new Blooddrop(random(width), random(height)));

}
}

void draw() {
println(blooddrops.size());
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
}
fill(200, 102, 0);
quad(0, 0, 0, 60, width, 40, width, 0);
int i = 0;
tissue.update();
tissue.display();
while (i < blooddrops.size()) {
r = blooddrops.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(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse
blooddrops.remove(i); //if it is, reset the raindrop raindrops.add(new Raindrop(random(0, width), 0));
}
if (r.loc.y > height + r.diam/2) { //check to see if the raindrop goes below the bottom of the screen
blooddrops.remove(i); //if it does, reset the raindrop
blooddrops.add(new Blooddrop(random(0, width), 0));
float rand = random(1);
if (rand <= .75) {
blooddrops.add(new Blooddrop(random(0, width), 0));
}
}
if (tissue.isCatching(r)) {

blooddrops.remove(i);

blooddrops.add(new Blooddrop(random(width),0));

}
i ++;
if (i>= 500) {
background(0);
textSize(50);
fill(200,0,0);
text("Game Over, You Lose!", width/2, height/2);
textAlign(CENTER);
}
}
}