diff --git a/raindropGameCode/Bucket.pde b/raindropGameCode/Bucket.pde new file mode 100644 index 0000000..4e28c0c --- /dev/null +++ b/raindropGameCode/Bucket.pde @@ -0,0 +1,14 @@ +class Bucket { + PVector loc; + float diam; //creates a class "Bucket" with a float for diameter and vector for location + Bucket(float tdiam) { + diam=tdiam; //diameter can be chosen by the player before playing to increase difficulty(or decrease) + loc=mouse; //the location of the bucket is set to the vector"mouse" + } + void display() { +loc=mouse; + + fill(50, 240, 9); + ellipse(loc.x, loc.y, diam, diam); //creates a function to display the bucket as a green ball at the mouse location + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..5eb31cc 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,83 @@ -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 - +int score1; //declares scoreing integer and initializes as "0" +Bucket b= new Bucket(5); // creates a bucket using the "Bucket" class and b as the name +ArrayList raindrops = new ArrayList(); //creates an array list for the class "raindrops" +PVector mouse; //creates a Pvector to use as the mouse location 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(); //initializes the mouse as a Pvector + raindrops.add(new Raindrop(random(width), 0)); // initializes the raindrop arraylist } void draw() { - mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + mouse.set(mouseX, mouseY); //sets the mouse Pvector as moouseX and 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)); //adds a new raindrop to the Arraylist for raindrops as "r" + for (int i = raindrops.size()-1; i >= 0; i--) { //keeps it from flashing the raindrops + Raindrop r = raindrops.get(i); //gets "r" from the Array List + r.display(); //uses the function to display the raindrops + r.fall(); //" to make the raindrops fall + if (r.contact(mouse)) { + r.reset(); // in the raindrop hits the bucket, it will reset back to the top + + score1++; //if the player hits a raindrop with the bucket, they score a point + if (r.loc.y > height + r.diam/2) { // if the raindrop goes below the screen, it goes back to the top + r.reset(); + } + } + textSize(50); + text(score1, width/2 - 50, 50); //>sets the text size, placement and sets it as the score of the game + textAlign(CENTER); + b.display(); //displays the bucket + if (score1> 50) { //if the score is greater than 50, the player see's a "win" screen + background(0); + textSize(50); + text("Congrats, You scored 50 Points!", width/2 - 50, 50); + textAlign(CENTER); + } } } + + + +class Raindrop { + PVector loc, vel, grav; + int diam; //creates the "raindrop" class by declaring the Pvectors "loc, vel and grav" snf the integer "diam" and the color"c" + color c; + + Raindrop(float x, float y) { //shows that the raindrop class needs an x and a y float as a perameter + loc = new PVector(x, y); + c = color(255); + vel = PVector.random2D(); //initializes loc as a new pvector with x and y, c as white, vel as a random vector, multiplies vel by 30, and adds gravity to the velocity + vel.mult(10); + diam= 30; + grav = new PVector(0, .7); + } + + void fall() { + vel= vel.add(grav); //function that adds grav to vel, or gravity to velocity, making it fall + loc.add(vel); + } + void display() { + fill(c); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); //displays the raindrops as ellipses at "x and y" using the variable "diam " as the diameter + } + void reset() { + + loc.x=random(0, width); + loc.y=0; + vel = new PVector(0, -4); //creates the reset function so that if it is started, it will put the raindrop to a random location at x=random y=0 + + vel= vel.add(grav); //also resets the gravity so it is not going too fast + loc.add(vel); + } + boolean contact(PVector bucket) { + loc.dist(mouse); + if (loc.dist(mouse) 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 +// } +// i++; +// } +// b.display(); + +// textSize(50); //setting text adjustments for the score 1 +// text(score1, width/2 - 50, 50); // " +// textAlign(CENTER); //" +} + + + +class Raindrop { + PVector loc, vel, grav; + int diam; + color c; + + Raindrop(float x, float y) { + loc = new PVector(x, y); + c = color(255); + vel = PVector.random2D(); + vel.mult(10); + diam= 30; + grav = new PVector(0, .7); + } + + void fall() { + vel= vel.add(grav); + loc.add(vel); + } + void display() { + fill(c); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); + } + void reset() { + + loc.x=random(0, width); + loc.y=0; + vel = new PVector(0, -4); + //vel.mult(10); + vel= vel.add(grav); + loc.add(vel); + } + boolean contact(PVector bucket) { + loc.dist(mouse); + if (loc.dist(mouse)