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
22 changes: 22 additions & 0 deletions raindropGameCode/Catcher.pde
Original file line number Diff line number Diff line change
@@ -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);
}
}
39 changes: 39 additions & 0 deletions raindropGameCode/raindrop.pde
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
107 changes: 89 additions & 18 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -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 <Raindrop> rain = new ArrayList <Raindrop>(); //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
}
}
}
40 changes: 40 additions & 0 deletions raindropGameCode/score.pde
Original file line number Diff line number Diff line change
@@ -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;
}
}
}