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
41 changes: 41 additions & 0 deletions raindropGameCode/Bad.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Bad { //new class called Bad
PVector loc, vel, a; //new PVectors loc, vel, a
int r, diam; //initialize variables r, diam



Bad(float x, float y) { //float coordinates of Bad
diam = 50; //diam equals 50
loc = new PVector(random(diam, width-diam), 0); //initialize loc PVector
vel = new PVector(0, random(1, 10)); //initialize vel PVector
a = new PVector(0, 0.001); //initialize a PVector
}


void display() {
fill(0); //set fill to black
noStroke(); //no stroke
ellipse(loc.x, loc.y, diam, diam); //draw ellipse for raindrops
}

void fall() {
loc.add(vel); //add velocity to the Bad raindrop
vel.add(a); //add acceleration to the velocity
}

boolean isInContactWith(Catcher c) { //the Bad raindrop is in contact with the catcher...
if (c.loc.dist(loc)<c.diam/2 + diam/2) { //if it is touching the coordinates of the catcher...
return true; //return true
}
else{ //if not...
return false; //return false
}
}



void reset() {
loc.x = random(width); //pick a random x-value for the Bad raindrop
loc.y = 0; //set the y-value to 0
}
}
23 changes: 23 additions & 0 deletions raindropGameCode/Catcher.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Catcher { //new class called Catcher
PVector loc; //new PVector loc
int diam, b, c; //initialize variables diam, b, c

Catcher(float w, float v) { //float coordinates of Catcher
diam = 100; //diam equals 100
loc = new PVector(w, v); //initialize loc PVector
}

void bucket(float x, float y) { //float cooridinates of bucket
fill(0); //set fill to black
ellipse(x, y, diam, diam); //draw ellipse for bucket
noStroke(); //no stroke
}

void reset() {
loc.x = random(width); //pick a random x-value for the catcher
loc.y = 0; //set the y-value to 0
}
void update(){
loc.set(mouseX,mouseY); //update the location of the catcher
}
}
40 changes: 40 additions & 0 deletions raindropGameCode/Raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Raindrop { //new class called Raindrop
PVector loc, vel, a; //new PVectors loc, vel, a
int r, diam; //initialize variables r, diam



Raindrop(float x, float y) { //float coordinates of Raindrop
diam = 50; //diam equals 50
loc = new PVector(random(diam, width-diam), 0); //initialize loc PVector
vel = new PVector(0, random(1, 10)); //initialize vel PVector
a = new PVector(0, 0.001); //initialize a PVector
}


void display() {
fill(255); //set fill to white
noStroke(); //no stroke
ellipse(loc.x, loc.y, diam, diam); //draw an ellipse
}

void fall() {
loc.add(vel); //add velocity to raindrop
vel.add(a); //add acceleration to velocity
}

boolean isInContactWith(Catcher c) { //the raindrop is in contact with the catcher...
if (c.loc.dist(loc)<c.diam/2 + diam/2) { //if the raindrop is touching to coordinates of the catcher...
return true; //return true
} else { //if not...
return false; //return false
}
}



void reset() {
loc.x = random(width); //choose a random x-value for the raindrop
loc.y = 0; //set the y-value to 0
}
}
17 changes: 17 additions & 0 deletions raindropGameCode/Score.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Score { //new class called Score
int scoref = 0; //variable scoref equals 0

Score() {
textSize(50); //set text size to 50

}
void display() {
textSize(50); //set text size to 50
text("Score", 70, 50); //insert text
text(scoref, 200, 50); //insert text
}
void addScore() {
scoref ++ ; //increase score
}

}
106 changes: 87 additions & 19 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,94 @@
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> r = new ArrayList<Raindrop>(); //declare an Array List for the good raindrop
ArrayList <Bad> b = new ArrayList<Bad>(); //declare an Array List for the bad raindrop
PVector circle; //declare a PVector called circle
Catcher c; //declare c as a variable for the Catcher class
Score s; //declare s as a variable for the Score class
int mode = 0; //initialize variable mode

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
size(1200, 800); //set canvas size
circle = new PVector(); //initialize circle PVector. value is irrelevant since it will be set at the start of void draw(){}
r.add(new Raindrop(random(width), 0)); //add new Raindrop
b.add(new Bad(random(width), 0)); //add new Bad raindrop
c = new Catcher(random(width), 0); //add new Catcher
s = new Score(); //add new Score
}

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) { //if the mode is set to 0...
background(0); //set background to black
textSize(30); //set text size to 30
textAlign(CENTER); //align the text to the center of the screen
text("Raindrop Game!", 600, 300); //insert text
text("Catch only the white raindrops. Press ENTER to begin.", width/2, height/2); //insert text
}
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 (keyCode==ENTER) { //if the ENTER key is pressed...
mode = 1; //set the mode to 1
}
}
if (mode == 1) { //if the mode is set to 1...
circle.set(mouseX, mouseY); //set value of circle as mouseX,mouseY
background(0, 200, 255); //set the background color
r.add(new Raindrop(random(width), 0)); //add new Raindrop
b.add(new Bad(random(width), 0)); //add new Bad raindrop
c.bucket(mouseX, mouseY); //catcher bucket
c.update(); //update the catcher
s.display(); //display the score
for (int i = r.size()-1; i>=0; i--) { //keep making new raindrops
Raindrop d= r.get(i); //add Raindrop d
d.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity
d.display(); //display the raindrop
if (d.isInContactWith(c)) { //check to see if the raindrop is in contact with the point represented by the Catcher
r.remove(i); //if it is, remove the raindrop
s.addScore(); //increase the score
}
if (d.loc.y > height + d.diam/2) { //check to see if the raindrop goes below the bottom of the screen
r.remove(i); //if it does, remove the raindrop
}
}

for (int i = b.size()-1; i>=1; i--) { //keep makng new bad raindrops
if (b.size()<200) { //if there are less than 200 bad raindrops on the screen...
Bad bd= b.get(i); //add new bad raindrops

bd.fall(); //make the bad raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity
bd.display(); //display the bad raindrop
if (bd.isInContactWith(c)) { //check to see if the bad raindrop is in contact with the point represented by the Catcher
b.remove(i); //if it is, remove the bad raindrop
mode = 2; //set the mode to 2
}
if (bd.loc.y > height + bd.diam/2) { //check to see if the bad raindrop goes below the bottom of the screen
b.remove(i); //if it does, remove the bad raindrop
}
}

if (mode == 2) { //if the mode is set to 2...
background(0); //set the background to black
fill(0, 200, 255); //set the color of the text
textAlign(CENTER); //align the text to the center of the screen
textSize(40); //set the text size to 40
text("You Lose!!!", width/2, height/2); //insert text
text("Press DELETE to return to the start screen", width/2+50, height/2+50); //insert text
noLoop(); //do not loop
if (key==DELETE) { //if the DELETE key is pressed...
mode = 0; //set the mode to 0
}
}


if (scoref == 50) { //if the score reaches 50...
mode = 3; //set the mode to 3
}
if (mode == 3) { //if the mode is set to 3...
background(0); //set the background to black
fill(0, 200, 255); //set the color of the text
textAlign(CENTER); //align the text to the center of the screen
textSize(40); //set the text size to 40
text("You WIN!!!", width/2, height/2); //insert text
text("Press BACKSPACE to return to the start screen", width/2+50, height/2+50); //insert text
noLoop(); //do not loop
}
if(keyCode == BACKSPACE) { //if the BACKSPACE key is pressed...
mode = 0; //set the mode to 0
}
}