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
56 changes: 56 additions & 0 deletions raindropGameCode/Raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
PVector loc, vel, g; //declare a P
class Raindrop {
color c;
int diam;


Raindrop(int tdiam) {
diam=30;
loc = new PVector(width/2, 50);
c=color(0, random(150, 255), random(10, 100));
vel= PVector.random2D();
g= new PVector(0, .25);
}
void display() {
fill(c);
noStroke();
ellipse(loc.x, loc.y, diam, diam);
}
void fall() {
loc.add(vel);
vel.add(g);
}
void reset() {
loc.x=random(width);
loc.y=0;
vel= PVector.random2D();
}
}
boolean isInContactWith(Catcher death) {
if ( loc.dist(mouse)<diam/2) { //makes the catcher move
return true; //makes the catcher do something
} else { //if it is not within the distance to the mouse
return false; // then it does not catch
}
}

class Catcher { // start the catcher class
color c; // insert the variable for the class
int diam;// insert the variable for the class
PVector loc;// insert the variable for the class

Catcher (int tdiam, float x, float y ) {//catcher builder
c=color(0); // change the color
diam=tdiam; // makes the diam matter
loc= new PVector(mouseX, mouseY); // set the pvector as the base for movement
}

void display() { // display function
fill(c); // makesd the color to display it
noStroke(); // makes the stroke gone so the edge is gone
ellipse (mouseX, 380, diam*2, 20); // makes the catcher
}
void move() { // move function
loc.set(mouseX, 380); // makes the catcher able to move
}
}
59 changes: 38 additions & 21 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
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

int co=20; //initialize co
PVector mouse; // initialize mouse
int score; //initialize score
Raindrop[] r = new Raindrop[co]; // new raindrop array list
Catcher death;//makw catcher death

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(600, 400);// size of background
mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){}
death = new Catcher(30, mouseX, mouseY); // new catcher death is made
int i=0;//declare i
while (i<co) {
r[i]= new Raindrop(100);// make one hundred raindrops
i++;// add new i to keep the raindrops being made every so often frames
}
frameRate(50);// increase framerate to make the game more fluid
}

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 (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 mouse as a vector
int i=0; //make i a zero for the block of code
background(0, 100, 255); //set blue colored background
while (i<co) {
r[i].fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity
r[i].display(); //display the raindrop
if (r[i].isInContactWith(death)) { //check to see if the raindrop is in contact with the point represented by the Catcher called death
r[i].reset(); //if it is, reset the raindrop
score++; // add one to score for every raindrop caught
}
if (r[i].loc.y > height + r[i].diam/2) { //check to see if the raindrop goes below the bottom of the screen
r[i].reset(); //if it does, reset the raindrop
}
i++; //add one to i to keep the raindrops functioning
fill(0); //makes score black
textSize(30); // asigns score text size
text(score, width/2, height/2); // writes score
death.display(); // display the shape death
death.move(); //make death move
if(score = 30){
background(0);
text("you win",300,200);
}
}
}
}