Skip to content
19 changes: 19 additions & 0 deletions raindropGameCode/Catcher.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Catcher { //creating the catcher
PVector loc;
int diam;
PImage catcher; //the catcher will be an image

Catcher (int tdiam) { //creating the catcher
loc=new PVector() ; //location of the catcher is a
diam=tdiam;
catcher = loadImage("lantern.png");
}

void display() {
image(catcher, loc.x, loc.y); //image as catcher
}

void update() {
loc.set(mouseX-25, mouseY-25); //where the raindrops will hit the catcher
}
}
Binary file added raindropGameCode/data/ball.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raindropGameCode/data/court.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raindropGameCode/data/forest.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raindropGameCode/data/hoop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raindropGameCode/data/lantern.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raindropGameCode/data/nike.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added raindropGameCode/data/not.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 70 additions & 13 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
PImage not;
PVector mouse; //declare a P
Raindrop r; //declare a new Raindrop called r

ArrayList <Raindrop> raindrops = new ArrayList <Raindrop>();
Catcher ca;
int score;
float start;
float diam;
PImage forest;
// 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

//declaring variables

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
start=1;
size(1200, 800); // sets size of canvas
mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){}
ca=new Catcher(100); //initialize the cathcher
diam=50;
forest=loadImage("forest.jpg");
}


void draw() {
if (start == 1) { //initial screen
background(0);
textSize(32); //text size
fill(240, 53, 0);
text("Catch the Light!", width/2-150, 350); //text will be "Play Pong"
text("Press any Key to Start", width/2-175, height/2); //text will be "Press any Key"
if (keyPressed == true) { //if any key is pressed
start = 2; //the game will start
}
}

if (start ==2) { //when the game starts

game(); //this will be the game that starts and the code for the game is below
}
}
void game() { //code for the actual game
background(0);
raindrops.add(new Raindrop(random(width), 0)); //initialize the image

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
fill(255, 233, 101);
ellipse(mouseX+20, mouseY+60, diam, diam);

for (int e =raindrops.size()-1; e>=0; e--) {
Raindrop ball = raindrops.get(e); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity
ball.display(); //display the raindrop
ball.fall(); //make the balls come down
if (ball.isInContactWith(ca)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse
ball.reset(); //if it is, reset the raindrop
score +=1;
diam += 0.3;
}
if (ball.loc.y > height + ball.diam/2) { //check to see if the raindrop goes below the bottom of the screen
ball.reset(); //if it does, reset the raindrop
score-=1; // add one to the score
}
}
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
ca.display(); //display the catcher
ca.update(); //update the catcher
textSize(32);
fill(252, 250, 254);
text(score, width/2, 700);
if (score>1) { //when the score is more than 275 aka player has missed more than 275 balls
gameover(); //the player wins the game and it ends the game
}
}

void gameover() { //code to end game
not(); //backrgound for final screen
textSize(48);
fill(255);
text("You Win!", width/2-100, height/2);
}


void not() { //image function for end of game background
background(0);
}
38 changes: 38 additions & 0 deletions raindropGameCode/raindrop_class.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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(255, 233, 101);
}

//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 (ca.loc.dist(loc) < ca.diam/2 + diam/2 ) {
return true; //if it hits any part of the catcher reset the raindrop
} else {
return false;
}
}
}