diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde new file mode 100644 index 0000000..3cfcb30 --- /dev/null +++ b/raindropGameCode/Catcher.pde @@ -0,0 +1,22 @@ + +class Catcher { + PVector loc; + color c; + float diam; + + Catcher() { + diam = 100; + loc = new PVector(); + c = color(255); + } + + //after declaring fields and setting up constructors, you can define your methods + void display() { + fill(c); + noStroke(); + ellipse(loc.x, loc.y, diam, diam); + } + void update() { + loc.set(mouseX,mouseY); + } +} \ No newline at end of file diff --git a/raindropGameCode/raindrop.pde b/raindropGameCode/raindrop.pde new file mode 100644 index 0000000..4162a89 --- /dev/null +++ b/raindropGameCode/raindrop.pde @@ -0,0 +1,39 @@ +class Raindrop { + PVector loc, vel, acc; + float diam; + color c; + + Raindrop(float x,float y) { + diam = random(20,50); + loc = new PVector(random(diam, width-diam), 0); + vel= new PVector(0, random(15)); + c = color(0, 0, random(255)); + } + + //after declaring fields and setting up constructors, you can define your methods + void display() { + fill(c); + noStroke(); + for (int i = 2; i < diam/2; i++ ) { + ellipse(loc.x,loc.y + i*4,i*2,i*2); + } + + } + void fall() { + vel.limit(5); + loc.add(vel); + } + + void reset() { + loc.y=0; + loc.add(vel); + } + + boolean isInContactWith(Catcher thing) { + if (thing.loc.dist(loc) < thing.diam/2 + diam/2 ) { + return true; //if it hits any part of the catcher reset the raindrop + } else { + return false; + } + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..d44c220 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,97 @@ -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 - +ArrayList rain = new ArrayList (); //declare a new Raindrop called r +Catcher c;//other classes declared +Score s; +int mode=0; //for start screen 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(); + rain.add(new Raindrop(width/2, height/2)); + c = new Catcher(); + s=new Score(); } +//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 - 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 (mode==0) { //start screen and adding text and instructions + background(255); + textSize(100); + fill(0, 0, 255); + textAlign(CENTER, CENTER); + text("Raindrop Game", width/2, height/3); + textSize(30); + fill(0); + text("OBJECTIVE: CATCH AS MANY RAINDROPS AS POSSIBLE", width/2, height/2); + text("YOU GAIN A POINT FOR EACH RAINDROP YOU CATCH", width/2, height/2 + 40); + text("AND LOSE 2 POINTS FOR EVERY RAINDROP YOU MISS", width/2, height/2 +80); + text("YOU WIN WHEN U GET A SCORE OF 30 ", width/2, height/2+120); + text("AND LOSE IF YOUR SCORE GOES BELOW ZERO", width/2, height/2+160); + text("Click Screen and hit any key to start", width/2, height/2+200);//text for title screen + + if (keyPressed) { // title screen goes away if key is pressed + mode=1; + } } - 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 + if (mode==1) { //if statement to make the start screen go away when key is pressed + + background(200); + c.display(); + c.update(); + s.display(); + if (rain.size() < 10) { + rain.add(new Raindrop(width/2, height/2)); + } + + for (int i=rain.size()-1; i>=0; i--) { + Raindrop r = rain.get(i); + r.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + r.display(); + + 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 + s.subScore(); + } + + if (r.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + r.reset(); + s.addscore(); + } + } + + if (s.scoref(c)) { //if the score is the winscore display win screen + mode=2; + } + + if (s.scoref2(c)) { //if you lose display the lose + mode=3; + s.score = 0; + } } -} + + if (mode==2) { + background(0); + fill(255); + text("HOLLA YOU WON CONGRATS!!!", width/2, height/3); + text("Click To Play Again!!!", width/2, height/2); //win screen + text("Have Fun :)", width/2, height/2+40); + if (mousePressed) { + mode=0; //if you click mouse go back to start screen + s.score=0; //reset ther score + rain.clear(); //reset the raindrops + } + } + if (mode==3) { + + background(0); + fill(255); + text("YOU LOSE BETTER LUCK NEXT TIME", width/2, height/3); + text("Click Screen To Play Again ", width/2, height/2); //lose screen + text("you can do it this time :)", width/2, height/2+40); + if (mousePressed) { + mode = 0; //if you click mouse go back to start screen + s.score = 0; //reset ther score + rain.clear(); //reset the raindrops + } + } +} \ No newline at end of file diff --git a/raindropGameCode/score.pde b/raindropGameCode/score.pde new file mode 100644 index 0000000..5552ba1 --- /dev/null +++ b/raindropGameCode/score.pde @@ -0,0 +1,40 @@ +class Score { + int score=0; + + Score() { + fill(0); + textSize(30); + } + + //after declaring fields and setting up constructors, you can define your methods + void display() { + fill(0); + text("Score:", 50, 50); + text(score, 115, 50); + } + + void addscore() { //adds score + score=score+1; + } + void subScore() { //subtract score + score=score-2; + } + + boolean scoref (Catcher thing) { + + if (score==30) { //win score + return true; + } else { + return false; + } + } + boolean scoref2 (Catcher thing) { + + if (score<0) { //lose score + return true; + + } else { + return false; + } + } +} \ No newline at end of file