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
14 changes: 14 additions & 0 deletions raindropGameCode/Bucket.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Bucket {
PVector loc;
float diam; //creates a class "Bucket" with a float for diameter and vector for location
Bucket(float tdiam) {
diam=tdiam; //diameter can be chosen by the player before playing to increase difficulty(or decrease)
loc=mouse; //the location of the bucket is set to the vector"mouse"
}
void display() {
loc=mouse;

fill(50, 240, 9);
ellipse(loc.x, loc.y, diam, diam); //creates a function to display the bucket as a green ball at the mouse location
}
}
91 changes: 74 additions & 17 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
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 score1; //declares scoreing integer and initializes as "0"
Bucket b= new Bucket(5); // creates a bucket using the "Bucket" class and b as the name
ArrayList<Raindrop> raindrops = new ArrayList<Raindrop>(); //creates an array list for the class "raindrops"
PVector mouse; //creates a Pvector to use as the mouse location

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(); //initializes the mouse as a Pvector
raindrops.add(new Raindrop(random(width), 0)); // initializes the raindrop arraylist
}

void draw() {
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
mouse.set(mouseX, mouseY); //sets the mouse Pvector as moouseX and 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
raindrops.add(new Raindrop(random(width), 0)); //adds a new raindrop to the Arraylist for raindrops as "r"
for (int i = raindrops.size()-1; i >= 0; i--) { //keeps it from flashing the raindrops
Raindrop r = raindrops.get(i); //gets "r" from the Array List
r.display(); //uses the function to display the raindrops
r.fall(); //" to make the raindrops fall
if (r.contact(mouse)) {
r.reset(); // in the raindrop hits the bucket, it will reset back to the top

score1++; //if the player hits a raindrop with the bucket, they score a point
if (r.loc.y > height + r.diam/2) { // if the raindrop goes below the screen, it goes back to the top
r.reset();
}
}
textSize(50);
text(score1, width/2 - 50, 50); //>sets the text size, placement and sets it as the score of the game
textAlign(CENTER);
b.display(); //displays the bucket
if (score1> 50) { //if the score is greater than 50, the player see's a "win" screen
background(0);
textSize(50);
text("Congrats, You scored 50 Points!", width/2 - 50, 50);
textAlign(CENTER);
}
}
}



class Raindrop {
PVector loc, vel, grav;
int diam; //creates the "raindrop" class by declaring the Pvectors "loc, vel and grav" snf the integer "diam" and the color"c"
color c;

Raindrop(float x, float y) { //shows that the raindrop class needs an x and a y float as a perameter
loc = new PVector(x, y);
c = color(255);
vel = PVector.random2D(); //initializes loc as a new pvector with x and y, c as white, vel as a random vector, multiplies vel by 30, and adds gravity to the velocity
vel.mult(10);
diam= 30;
grav = new PVector(0, .7);
}

void fall() {
vel= vel.add(grav); //function that adds grav to vel, or gravity to velocity, making it fall
loc.add(vel);
}
void display() {
fill(c);
noStroke();
ellipse(loc.x, loc.y, diam, diam); //displays the raindrops as ellipses at "x and y" using the variable "diam " as the diameter
}
void reset() {

loc.x=random(0, width);
loc.y=0;
vel = new PVector(0, -4); //creates the reset function so that if it is started, it will put the raindrop to a random location at x=random y=0

vel= vel.add(grav); //also resets the gravity so it is not going too fast
loc.add(vel);
}
boolean contact(PVector bucket) {
loc.dist(mouse);
if (loc.dist(mouse)<diam+b.diam/2) { //makes a boolean for if the raindrop is touching the bucket or not, it is used to trigger the "reset" function as well as increase score
return true;
} else {
return false;
}
}
}
15 changes: 15 additions & 0 deletions raindropGameCodeWithAttemptAtArrayLists/Bucket.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Bucket {
PVector loc;
float diam;
Bucket(float tdiam) {
diam=tdiam;
loc=mouse;
}
void display() {


fill(0);
ellipse(mouseX, mouseY, diam, diam);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
float score1;
int count = 100;
Bucket b= new Bucket(100);
//Raindrop[] r= new Raindrop[count];
ArrayList Raindrops=new ArrayList();
PVector mouse; //declare a P
//Raindrop r; //declare a new Raindrop called r
//Bucket b;
// 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() {
Raindrop r = new Raindrop(random(width), 0);
Raindrops.add(r);


size(1200, 800);
mouse = new PVector();
//initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){}
int i=0;
while (i<count) {
// r[i]= new Raindrop(random(width), 0);
i++;
// r = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions
}
}

void draw() {

Raindrop r =(Raindrop) Raindrops.get(0);
r.fall();

int i=0;
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
background(0, 200, 255);
while (i<count) {
//b.disp();
// 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].contact(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse
// r[i].reset(); //if it is, reset the raindrop

// score1++;
// }
// 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++;
// }
// b.display();

// textSize(50); //setting text adjustments for the score 1
// text(score1, width/2 - 50, 50); // "
// textAlign(CENTER); //"
}



class Raindrop {
PVector loc, vel, grav;
int diam;
color c;

Raindrop(float x, float y) {
loc = new PVector(x, y);
c = color(255);
vel = PVector.random2D();
vel.mult(10);
diam= 30;
grav = new PVector(0, .7);
}

void fall() {
vel= vel.add(grav);
loc.add(vel);
}
void display() {
fill(c);
noStroke();
ellipse(loc.x, loc.y, diam, diam);
}
void reset() {

loc.x=random(0, width);
loc.y=0;
vel = new PVector(0, -4);
//vel.mult(10);
vel= vel.add(grav);
loc.add(vel);
}
boolean contact(PVector bucket) {
loc.dist(mouse);
if (loc.dist(mouse)<diam+b.diam/2) {
return true;
} else {
return false;
}
}
}