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
16 changes: 16 additions & 0 deletions raindropGameCode/Bucket.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Bucket {
PVector loc; //initialize location pvector
float diam; //float diameter
color c; //declare color

Bucket (int tDiam) {
diam = tDiam; //set another variable equal to diameter
loc = new PVector(mouseX, mouseY); //set pvector to mouse coords
c = color(155); //set color variable
}
void display () { //create new command to display bucket
fill(255, 100, 0); //set color
ellipse(mouseX, mouseY, diam, diam); //set bucket location and size
fill(255); //set color
}
}
16 changes: 16 additions & 0 deletions raindropGameCode/bucket.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Bucket {
PVector loc; //initialize location pvector
float diam; //float diameter
color c; //declare color

Bucket (int tDiam) {
diam = tDiam; //set another variable equal to diameter
loc = new PVector(mouseX, mouseY); //set pvector to mouse coords
c = color(155); //set color variable
}
void display () { //create new command to display bucket
fill(255, 100, 0); //set color
ellipse(mouseX, mouseY, diam, diam); //set bucket location and size
fill(255); //set color
}
}
Binary file added raindropGameCode/data/storm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions raindropGameCode/raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Raindrop {
//declaring all information (fields) contained within the raindrop class
PVector loc, vel, acc; //intialize pvectors
int diam; //declare diameter
color c; //declare color variable

//this is a constructor. you can have more than one constructor for a given class
Raindrop(float x, float y) {

diam = 20; //set diameter
loc = new PVector(x, y); //set location vector
vel = new PVector(0, 0.5); //set velocity vector
acc = new PVector(0, .1); //set acceleration vector
c = color(200, 200, 255, 200); //set color
loc.add(vel); //add velocity to location
}

void fall() { //create new command to make drop fall
loc.add(vel); //add velocity to location
vel.add(acc); //add acceleration to velocity
}

void display() { //create new command to display drop
fill(c); //set color
noStroke(); //delete outline
ellipse(loc.x, loc.y, diam, diam); //set ellipse to show drop
}

boolean isInContactWith(PVector mouse) { //if drop is in contact with mouse, return true
if (loc.dist(mouse) < diam/2 + b.diam/2) {
return true;
} else {
return false;
}
}


void reset() { //create new command to reset the drop's position
loc = new PVector(random(diam, width-diam), 0); //reset location
vel = new PVector(0, 0.5); //reset velocity
acc = new PVector(0, 0.1); //reset acceleration
}
}
127 changes: 110 additions & 17 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,119 @@
PVector mouse; //declare a P
Raindrop r; //declare a new Raindrop called r
PVector mouse; //declare a P //<>//
int score; //declare variable for score
Bucket b; //declare a new Bucket called b //declare a new Bucket called b
PImage storm; //declare image
float menu; //declare variable for menu

ArrayList <Raindrop> r = new ArrayList<Raindrop>(); //create arraylist


// 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() {
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

void setup() { //this runs once
r.add(new Raindrop(random(width), 0)); //initialize r. The parameters are the coordinates of the initial locations of the raindrops
score = 0; //add score value
size(1200, 800); //set canvas size
mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){}
b = new Bucket(60); //initialize b. The parameter is the width of the bucket
imageMode(CENTER); //center image placement
storm = loadImage("storm.jpg"); //load image of storm
}

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
void draw() { //this runs repeatedly

if (menu==0) { //sets start screen
background(150, 150, 255); //set background
textAlign(CENTER); //aligns image to center
textSize(100); //set text size
text("RAINDROP GAME", width/2, height/2 - 40); //add start text
textSize(40); //set text size
text("press enter to begin", width/2, height/2 + 40); //add text with instructions


if (keyPressed) {
if (key == ENTER) {
menu=1;
}
} //if enter is pressed, start game
} else if (menu==1) { //runs game code
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
background(0, 0, 50); //set background
image(storm, width/2, height/2, storm.width, storm.height); //loads background image
r.add(new Raindrop(random(width), 0)); //add a new raindrop on the top of the screen at a random x coordinate

for (int i = r.size()-1; i >= 0; i--) {
Raindrop x = r.get(i);
x.display(); //display the raindrop
x.fall(); //have the raindrop fall
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
score = score+1; //if it is, add one to score
r.remove(i); //remove the raindrop at your mouse coords
}
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
r.remove(i); //remove raindrop at bottom of screen
}
}

fill (200); //set color of score text
ellipse(-20, -30, 30, 100);
b.display(); //displays bucket
textSize(50); //set text size
text(score, 100, 100); //place score text
if (score>=200) {
menu=2;
} //if score is 200, run win screen
} else if (menu==2) { //set win screen
background(150, 150, 255); //set background
textAlign(CENTER); //align text to center
textSize(100); //set text size
fill(random(255), random(255), random(255)); //set random fill
text("YOU WIN GG", width/2, height/2 - 40); //set "you win" text
textSize(40); //set text size
fill(255); //set color
text("press ENTER to play again", width/2, height/2 + 40); //give instructions text
text("press TAB to enter freeplay", width/2, height/2 + 90); //give instructions text


if (keyPressed) {
if (key == ENTER) {
menu=1;
score=0; //if enter is pressed, reset score and game
} else if (key == TAB) {
menu=3;
} //if tab is pressed, rest game but not score
}
} else if (menu==3) {
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
background(0, 0, 50); //set background
image(storm, width/2, height/2, storm.width, storm.height); //place background image
r.add(new Raindrop(random(width), 0)); //place raindrop

for (int i = r.size()-1; i >= 0; i--) {
Raindrop x = r.get(i); //get raindrop info
x.display(); //display raindrop
x.fall(); //set raindrop to fall
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
score = score+1; //if it is, add one to score
r.remove(i); //remove the raindrop at your mouse coords
}
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
r.remove(i); //remove raindrop at bottom of screen
}
}

fill (200); //set color
ellipse(-20, -30, 30, 100); //place ellipse
b.display(); //display bucket
textSize(50); //set text size
text(score, 100, 100); //place score text

}
}
}
16 changes: 16 additions & 0 deletions raindropGameCode/raindropGameCode/bucket.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Bucket {
PVector loc;
float diam;
color c;

Bucket (int tDiam) {
diam = tDiam;
loc = new PVector(mouseX, mouseY);
c = color(155);
}
void display () {
fill(255, 100, 0);
ellipse(mouseX, mouseY, diam, diam);
fill(255);
}
}
Binary file added raindropGameCode/raindropGameCode/data/storm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions raindropGameCode/raindropGameCode/raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Raindrop {
//declaring all information (fields) contained within the raindrop class
PVector loc, vel, acc;
int diam;
color c;

//this is a constructor. you can have more than one constructor for a given class
Raindrop(float x, float y) {
diam = 20;
loc = new PVector(x, y);
vel = new PVector(0, 0.5);
acc = new PVector(0, .1);
c = color(200, 200, 255, 200);
loc.add(vel);
}

void fall() {
loc.add(vel);
vel.add(acc);
}

void display() {
fill(c);
noStroke();
ellipse(loc.x, loc.y, diam, diam);
}

boolean isInContactWith(PVector mouse) {
if (loc.dist(mouse) < diam/2 + b.diam/2) {
return true;
} else {
return false;
}
}

void reset() {
loc = new PVector(random(diam, width-diam), 0);
vel = new PVector(0, 0.5);
acc = new PVector(0, 0.1);
}
}
116 changes: 116 additions & 0 deletions raindropGameCode/raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
PVector mouse; //declare a P //<>//
int score;
Bucket b; //declare a new Bucket called b
PImage storm; //declare image
float menu;

ArrayList <Raindrop> r = new ArrayList<Raindrop>();

// 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() {
r.add(new Raindrop(random(width), 0));
score = 0; //add score value
size(1200, 800); //set canvas size
mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){}
b = new Bucket(60); //initialize b. The parameer is the width of te bucket
imageMode(CENTER);
storm = loadImage("storm.jpg");
}

void draw() {

if (menu==0) {
background(150, 150, 255);
textAlign(CENTER);
textSize(100);
text("RAINDROP GAME", width/2, height/2 - 40);
textSize(40);
text("press enter to begin", width/2, height/2 + 40);


if (keyPressed) {
if (key == ENTER) {
menu=1;
}
}
} else if (menu==1) {
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
background(0, 0, 50); //set background
image(storm, width/2, height/2, storm.width, storm.height);
r.add(new Raindrop(random(width), 0));

for (int i = r.size()-1; i >= 0; i--) {
Raindrop x = r.get(i);
x.display();
x.fall();
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
score = score+1; //if it is, add one to score
r.remove(i);
}
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
r.remove(i);
}
}

fill (200);
ellipse(-20, -30, 30, 100);
b.display();
textSize(50); //set text size
text(score, 100, 100); //place score text
if (score>=50) {
menu=2;
}
} else if (menu==2) {
background(150, 150, 255);
textAlign(CENTER);
textSize(100);
fill(random(255), random(255), random(255));
text("YOU WIN GG", width/2, height/2 - 40);
textSize(40);
fill(255);
text("press ENTER to play again", width/2, height/2 + 40);
text("press TAB to enter freeplay", width/2, height/2 + 90);


if (keyPressed) {
if (key == ENTER) {
menu=1;
score=0;
} else if (key == TAB) {
menu=3;
}
}
} else if (menu==3) {
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
background(0, 0, 50); //set background
image(storm, width/2, height/2, storm.width, storm.height);
r.add(new Raindrop(random(width), 0));

for (int i = r.size()-1; i >= 0; i--) {
Raindrop x = r.get(i);
x.display();
x.fall();
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
score = score+1; //if it is, add one to score
r.remove(i);
}
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
r.remove(i);
}
}

fill (200);
ellipse(-20, -30, 30, 100);
b.display();
textSize(50); //set text size
text(score, 100, 100); //place score text
}
}