diff --git a/raindropGameCode/Raindropclass.pde b/raindropGameCode/Raindropclass.pde new file mode 100644 index 0000000..5ae1a8c --- /dev/null +++ b/raindropGameCode/Raindropclass.pde @@ -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) 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; + } + } + + +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..17fa95e 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -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 blooddrops = new ArrayList(); //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); + } + } +} \ No newline at end of file