Skip to content
29 changes: 29 additions & 0 deletions raindropGameCode/Bucket.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Bucket {

//declare vector and variables
PVector loc;
float c;
float wd;
float ht;

//declare Bucket class
Bucket() {
//define location of bucket
loc = new PVector(mouseX, mouseY);

//define dimensions of bucket
wd = 100;
ht = 20;

//define color of bucket
c = color(25, 165, 165);
}

void display() {
//color the bucket interior and background as determined by the floated variable "c"
fill(c);
stroke(c);
//display the bucket centered at the mouse
quad(mouseX - wd/2, mouseY - ht/2, mouseX + wd/2, mouseY - ht/2, mouseX + wd/2 - 5, mouseY + ht/2, mouseX - wd/2 + 5, mouseY + ht/2);
}
}
36 changes: 36 additions & 0 deletions raindropGameCode/Person.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Person {

//declare vectors
PVector loc, acc, vel;

//declare variables
float diam;
color c;

//define Person class
Person() {
//define diameter of ellipse
diam = 50;

//define variables for movement: location, velocity and acceleration
loc = new PVector(600, 800 - diam / 2);
vel = new PVector(0, 0);
acc = new PVector(.1, 0);

//color the person
c = color(25, 255, 125);
}

void display() {
//create method to draw the person
fill(c);
stroke(c);
ellipse(loc.x, loc.y, diam, diam);
}

void move() {
//create method to move the person based on their random acceleration
vel.add(acc); //add acceleration to the velocity
loc.add(vel); //add velocity to the position
}
}
64 changes: 64 additions & 0 deletions raindropGameCode/Raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//declare class
class Raindrop {

//declare vectors
PVector vel, loc, acc;

//declare variables
float diam;
color c;

Raindrop() { //construct the raindrop object
//set raindrop diameter
diam = 30;

//define variables for movement: location, velocity and acceleration
loc = new PVector(random(width), -20); //define initial starting location of raindrops
vel = new PVector(0, random(-10, 10)); //define initial speed of raindrops
acc = new PVector(0, .1); //define acceleration of raindrops' speed

//define color of raindrops
c = color(255);
}

void display() {
//color the raindrops
fill(c);
stroke(c);

//draw the ellipse that composes the raindrops
ellipse(loc.x, loc.y, diam, diam);
}

void reset() {
//create method to reset the raindrops' position and speed
vel = new PVector(0, random(-10, 10));
loc = new PVector(random(width), -20);
//increase acceleration of raindrops every time they are reset
acc.mult(1.5);
}

void fall() {
//create method to cause the raindrops to fall
vel.add(acc);
loc.add(vel);
}

boolean isInContactWith(float x1, float x2, float y1, float y2) {
//create boolean to return "true" if the raindrop's location lies within the four given points.
if (loc.x >= x1 && loc.x <= x2 && loc.y >= y1 && loc.y <= y2) {
return true;
} else {
return false;
}
}

boolean onGround() {
//create boolean to return "true" if the raindrop's location lies upon the lower edge of the canvas
if (loc.y >= height) {
return true;
} else {
return false;
}
}
}
141 changes: 124 additions & 17 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,133 @@
PVector mouse; //declare a P
Raindrop r; //declare a new Raindrop called r
//declare integers for the person's health, what menu is open, and what score is seen
int menu, health, score;

// 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
//create arraylist of raindrops to create many raindrops on-screen
ArrayList<Raindrop> r = new ArrayList<Raindrop>();

Bucket b = new Bucket();

Person p = new Person();


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
//set canvas size
size(1200, 800);

//color background
background(0, 200, 255);

//set initial score and health
health = 10;
score = 0;

//set initial menu to the start menu.
menu = 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 (menu == 0) { //create the start menu
//draw background every frame
background(0, 200, 255);

//write start menu text
textSize(120);
fill(255);
textAlign(CENTER);
text("RAINDROP BULWARK", width/2, 300);
textSize(40);
text("USE THE MOUSE TO SHIELD THE PERSON FROM THE RAIN!", width/2, 500);
text("PRESS 'R' TO START", width/2, 700);

} else if (menu == 1) { //create space for the game itself
//draw background every frame
background(0, 200, 255);

r.add(new Raindrop());
//draw a number of raindrops equal to the count interger
for (int i = r.size() - 1; i >= 0; i--) {
Raindrop rain = r.get(i); //retrieve a raindrop object
rain.display(); //display the raindrops
rain.fall(); //cause the raindrops to fall

//if the raindrops hit the ground, remove them from the canvas
if (rain.onGround()) {
r.remove(i);
}

//if the raindrops hit the bucket, remove them and increase the score by 1
if (rain.isInContactWith(mouseX - (b.wd / 2), mouseX + (b.wd / 2), mouseY - (b.ht / 2), mouseY + (b.wd / 2))) {
r.remove(i);
score ++;
}

//if the raindrops hit the person, remove them and decrease health by 1
if (rain.isInContactWith(p.loc.x - (p.diam / 2), p.loc.x + (p.diam / 2), p.loc.y - (p.diam / 2), p.loc.y + (p.diam / 2))) {
r.remove(i);
health --;
}
}

//draw the bucket at the given location
b.display();

//draw the person at the given location
p.display();

//change acceleration of Person class every frame
p.acc.mult(random(-2, 2));

//if the person hits the edge of the canvas, change direction
if (p.loc.x > width) {
p.vel.mult(-1);
p.loc.x = width;
} else if (p.loc.x < 0) {
p.vel.mult(-1);
p.loc.x = 0;
}

//cause the person to move
p. move();

//Create scoreboard at top of screen
fill(255);
rectMode(CENTER);
noStroke();
rect(width/2, 29, 240, 60);

//write text on scoreboard
textSize(20);
fill(0, 200, 255);
textAlign(CENTER);
text("HEALTH: " + health, width/2, 15);
text("DROPS CAUGHT: " + score, width/2, 45);

} else if (menu == 2) { //create the game over menu
//draw background every frame
background(0, 200, 255);

//write GAME OVER text
textAlign(CENTER);
fill(255);
textSize(120);
text("GAME OVER", width/2, 300);
text("YOUR SCORE: " + score, width/2, 500);
text("PRESS 'R' TO START", width/2, 700);
}
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 the r-key is pressed, restart the game
if (keyPressed == true) {
if (key == 'r' || key == 'R') {
menu = 1;
health = 10;
score = 0;
}
}
}

if(health == 0){
menu = 2;
}
}