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
18 changes: 18 additions & 0 deletions raindropGameCode/Catcher_Class.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Catcher { //declare variables
PVector loc; //vector location
PImage img; //image name
int diam = 75; //image diameter


Catcher() { //set values for variables
loc = new PVector();
loc.set(mouseX, mouseY); //location is set where the mouse travels
img = loadImage("umbrella.png"); //load image of the umbrella
}

void display() {
fill(0, 50, 200); //fill color
//ellipse(mouseX, mouseY, diam, diam);
image(img, mouseX, mouseY, diam, diam); //image moves where the mouse is
}
}
52 changes: 52 additions & 0 deletions raindropGameCode/Raindrop_Class.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Raindrop { //declare variables
PVector loc;
PVector vel, acc;
int diam;
float locx;
float locy;
float t;
int num;
PImage img;

Raindrop(float locx, float locy) { //set values for variables
t = random(200, 255);
vel = new PVector(0, random(1, 3));
acc = new PVector(0, random(.2));
loc = new PVector(locx, locy);
diam = 20;
img = loadImage("hail.png");
}

void display() {
fill(255, 255, 255, t); //fill display screen
noStroke();

image(img, loc.x - 50, loc.y -50, diam, diam); //image of "hail" movement downward

//ellipse(loc.x, loc.y, diam, diam);
}

void fall() { //coding for the hail to fall
loc.y += vel.y;
vel.add(acc); //adding velocity to hail going down
}

void reset() { //reset hail after it hits 0
loc.y = 0;
vel.y = 0;
}

void num() {
}

boolean isInContactWith(PVector c) {
boolean p;
float d = dist(loc.x, loc.y, mouseX, mouseY);
if (d-diam/2 >50) {
p = false;
} else {
p = true;
}
return p; //returns hail back on top once it is in contact with umbrella
}
}
Binary file added raindropGameCode/data/Rain background.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/hail.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/umbrella.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 44 additions & 13 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
PVector mouse; //declare a P
Raindrop r; //declare a new Raindrop called r
int count = 20;
int caught = 0;
//Raindrop [] x = new Raindrop[count];
ArrayList<Raindrop> drops = new ArrayList<Raindrop>(); //arraylist


Catcher c; //catcher class
// 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


void setup() {
void setup() { //set values for variables
c = new Catcher();
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(){}
drops.add(new Raindrop(random(width), 0));
//for (int i = 0; i < count; i++) {
// x[i] = new Raindrop(random(width), random(0)) ;
//}
}



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 ( drops.size() <2000) {
drops.add(new Raindrop(random(width), 0)); //adds raindrops at a random location on the x axis which is the top of the screen
}
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

mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
background(0, 200, 255); //set background
textSize(30); //set text size
c.display(); // //display catcher
text(caught,width/2,height/2); //display score at the center of the screen

for (int i = drops.size()-1; i >= 0; i--) { //raindrop coding
Raindrop x = drops.get(i);
x.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity
x.display(); //display the raindrop
if (x.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse
x.reset(); //if it is, reset the raindrop
caught++;
println(caught);
}
if (x.loc.y > height + x.diam/2) { //check to see if the raindrop goes below the bottom of the screen
x.reset(); //if it does, reset the raindrop
}
if (x.loc.x> mouseX) {
x.loc.x +=3;
}
if (x.loc.x< mouseX) {
x.loc.x -=3;
}
}
}
}