diff --git a/raindropGameCode/catcher.pde b/raindropGameCode/catcher.pde new file mode 100644 index 0000000..c448ec2 --- /dev/null +++ b/raindropGameCode/catcher.pde @@ -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); + } +} \ No newline at end of file diff --git a/raindropGameCode/data/ghost.png b/raindropGameCode/data/ghost.png new file mode 100644 index 0000000..12d5c32 Binary files /dev/null and b/raindropGameCode/data/ghost.png differ diff --git a/raindropGameCode/data/pacman.png b/raindropGameCode/data/pacman.png new file mode 100644 index 0000000..300bb87 Binary files /dev/null and b/raindropGameCode/data/pacman.png differ diff --git a/raindropGameCode/data/pinkghost.ico b/raindropGameCode/data/pinkghost.ico new file mode 100644 index 0000000..346f696 Binary files /dev/null and b/raindropGameCode/data/pinkghost.ico differ diff --git a/raindropGameCode/raindrop.pde b/raindropGameCode/raindrop.pde new file mode 100644 index 0000000..5290ee4 --- /dev/null +++ b/raindropGameCode/raindrop.pde @@ -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; + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..f63411c 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -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 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; + } +} \ No newline at end of file