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
Binary file added raindropGameCode/BUCKET.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions raindropGameCode/Catcher.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Catcher {//declare the bucket
float diam; // radius
color co; // color
PVector loc; // location

Catcher(float tempD) {//intialize/call
diam = tempD;
co = color(128, 128, 128);
loc = new PVector(0,0);
}

void setLocation(PVector m) {//where the bucket will temporarily be
loc.set(m.x,m.y);
}

void display() {//function for bucket appearance
noStroke();
fill(co);
ellipse(loc.x,loc.y, diam*4, diam*4);
}

// A function that returns true or false based on
// if the catcher intersects a raindrop
boolean intersect(Raindrop d) {
// Calculate distance
float distance = loc.dist(d.loc);

// Compare the length of the bucket to the raindrop
if (distance < diam + d.diam) {
return true;
} else {
return false;
}
}
}
35 changes: 35 additions & 0 deletions raindropGameCode/Raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Raindrop {//declare Raindrop
PVector loc, vel, acc;//variable for length, speed, color
float diam;
color co;


Raindrop() {//call functionality and intialize
diam=20;
loc=new PVector(random(0, width), 0);
vel=PVector.random2D();
acc=new PVector(0, .1);
co= color(204, 255, 255);
}
void display() {//function so raindrops appear
fill(co);
noStroke();
triangle(loc.x-diam/2, loc.y, loc.x, loc.y-40, loc.x+diam/2, loc.y);
ellipse(loc.x, loc.y, diam, diam);
}
boolean isInContactWith() {//raindrop is in contact with the mouse, does something
if (loc.y>height+diam/2) {
return true;
} else {
return false;//disappears
}
}
void fall() {//how the raindrops fall
vel.add(acc);
loc.add(vel);
}
void reset() {//when its over the screen, disappears
loc.y=0;
vel.y=0;
}
}
28 changes: 28 additions & 0 deletions raindropGameCode/Timer.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Timer {//declare the timer
int s;
int m;

Timer() {//initialize
s=0;
m=0;
}

void display() {//call functionality
fill(153, 204, 0);
textAlign(CENTER);//how the text will look like
textSize(50);
delay(1000);
if (s<=59) {//before it reaches 60 seconds, only the right hand side will change
text(m+":"+s, width/2, height/2);
s=s+1;
} else {//the left side will now change after 60 seconds
m=m+1;
s=0;
text(m+";"+s, width/2, height/2);
}
}
void reset(){//function so time resets when game over
m=0;
s=0;
}
}
Binary file added raindropGameCode/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 65 additions & 16 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,75 @@
PVector mouse; //declare a P
Raindrop r; //declare a new Raindrop called r

ArrayList<Raindrop> r= new ArrayList<Raindrop>(); //declare a new ArrayList called r for the raindrop
Catcher C;//declare Bucket
Timer timer;//declare Timer
PImage background;
// 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 mode=0;//0 is intro, 1 is normal play, 2 means game has ended

void setup() {//run settings once

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(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){}
//Initialize r. The parameters used are the initial x and y positions
C= new Catcher(20);//initalize catcher
timer= new Timer();//initialize timer
background= loadImage("background.jpg");
for ( int i=0; i<5; i++) {//for loop and arraylist.
r.add(new Raindrop ());
}
}
void draw() {//run settings in loop
if (mode==0) {//intro
fill(0, 255, 0);
imageMode(CENTER);//background
image(background, width/2, height/2);
textSize(20);
textAlign(CENTER);
fill(255);
text("WELCOME TO THE DROP", width/2, height/2-50);
text("YOU ARE TIMED. CATCH ALL THE RAINDROPS OR ELSE.", width/2, height/2+25);
text("PRESS ENTER TO START", width/2, height/2+50);
if (keyPressed==true) {
//if(keyCode==ENTER)
mode=1;
}
}

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==1) {//normal play
background(0);
mouse.set(mouseX, mouseY);//set value of mouse as mouseX,mouseY
C.setLocation(mouse);//call functions for catcher and raindrop
C.display();
timer.display();//call function for timer
for (int i=0; i<r.size(); i++) {
Raindrop rd= r.get(i);
rd.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity
rd.display(); //display the raindrop
if (C.intersect(rd)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse
r.remove(i); //remove the raindrops once it goes pass the height
}
//if (rd.loc.y > height + rd.diam/2) { //check to see if the raindrop goes below the bottom of the screen
// r.remove(i); //if it does, reset the raindrop
//}
if (rd.loc.y>height) {
mode=2;
}
}
}
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==2) {//game over screen
background(0);
fill(0, 255, 0);
textSize(20);
textAlign(CENTER);
text("GAME", width/2, height/2);
text("OVER", width/2, height/2+75);
text("PRESS ENTER TO PLAY AGAIN", width/2, height/2+150);
timer.reset();
if ( keyPressed==true) {
//if(keyCode==ENTER)
mode=0;//returns to the beginning screen and timer is reset
}
}
}
}