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.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Catcher { //declare new catcher
PVector loc;
PImage pacman;
//int diam;
Catcher() { //initiatize catcher variable
loc = new PVector();
// diam = cdiam;
pacman = loadImage("pacman.png");
}

void display() { //display catcher field
noTint();
image(pacman, loc.x, loc.y, 80, 80);
}
void update() { //mouse is with catcher
loc.set(mouseX, mouseY);
}
}
Binary file added raindropGameCode/data/ghost.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/pacman.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/pinkghost.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions raindropGameCode/raindrop.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Raindrop { //declaring all fields contained within Raindrop Class
PImage redghost;
PImage blueghost;
PImage pinkghost;
PVector loc, vel, grav;
int diam;
int score = 0;
color c;
Raindrop(float x, float y) { //initiatize constructor
diam = 25;
loc = new PVector(x, y);
vel = new PVector(random(-5, 5), random(-5, 5));
grav = new PVector(0, .001);
redghost = loadImage("ghost.png");
c = color(random(255),random(255),random(255));
}
void display() { //display ghosts with tint colors
tint(c);
image(redghost, loc.x, loc.y, diam, diam);

}
void fall() { //add velocity to ghosts
loc.y=loc.y + vel.y;
vel.add(grav);
}
void reset() { //reset ghosts when disappears off of screen back to top
loc.y=0;
vel.set(0, 10);
}
boolean isInContactWith(PVector mouse) { //ghosts disappear when catcher is in contact with mouse
float d = dist(loc.x, loc.y, mouse.x, mouse.y);
boolean a;
if (d < diam/2 + 35) {
a = true;
} else {
a = false;
}
return a;
}
}
65 changes: 50 additions & 15 deletions raindropGameCode/raindropGameCode.pde
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
PVector mouse; //declare a P
Raindrop r; //declare a new Raindrop called r

int score = 0; //declare variables
int count = 150;
int gameover;
PVector mouse;
ArrayList <Raindrop> raindrops = new ArrayList();
//Raindrop [] r = new Raindrop [count]; //declare a new Raindrop called r
Catcher c;
// 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);
void setup() { //initialize varialbes
size(1000, 800);
gameover = 1;
imageMode(CENTER); //center the image/text
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
imageMode(CENTER);
c = new Catcher();
raindrops.add(new Raindrop(random(width), 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 (gameover == 1) { //if game is running
mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY
background(0, 200, 255);
textSize(100); //score displays on screen
text(score, width/2, height/4);
raindrops.add(new Raindrop(random(width), 0));
c.update();
c.display();
for (int i = raindrops.size()-1; i >= 0; i--) { //array for raindrops
Raindrop r = raindrops.get(i);
r.display();
r.fall();
if (r.isInContactWith(mouse)) { //remove raindrop/ghost when in contact with mouse
raindrops.remove(i);
}
if (r.loc.y > height + r.diam/2) {
r.reset();
score = score + 1;
}
}
if (score == 51) { //gameover when score is 51
gameover = 0;
}
}
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 (gameover == 0){ //text GAME OVER on screen when game is over
textSize(200);
fill(#FF0808);
textSize(150);
textAlign(CENTER);
text("GAME OVER CLICK TO PLAY AGAIN", width/2, height/2);
}
}
if (mousePressed) { //freeze screen when game is over so ghosts and catcher remain still
raindrops.clear();
gameover = 1;
fill(255);
score = 0;
}
}