diff --git a/raindropGameCode/catcher.pde b/raindropGameCode/catcher.pde new file mode 100644 index 0000000..afea917 --- /dev/null +++ b/raindropGameCode/catcher.pde @@ -0,0 +1,26 @@ +class Bucket { //declare new class for catching raindrops + PVector loc; + PImage s; + float c, d; //control size of image + + Bucket () { //create constructor + s = loadImage("snowman.png"); + loc = new PVector (random(width), random(height)); + imageMode(CENTER); //centers image + c = 250; + d = 278; + } + + void display () { //function display bucket + image (s, loc.x, loc.y, c, d); //draw image + } + + void update () { + loc.set(mouseX, mouseY); //makes loc = mouse + } + + void decrease (float a) { //function to decrease size of img + c = c- a; //decrease width + d = d - a; //decrease height + } +} \ No newline at end of file diff --git a/raindropGameCode/data/snowman.png b/raindropGameCode/data/snowman.png new file mode 100644 index 0000000..8740269 Binary files /dev/null and b/raindropGameCode/data/snowman.png differ diff --git a/raindropGameCode/data/sun.png b/raindropGameCode/data/sun.png new file mode 100644 index 0000000..38ece12 Binary files /dev/null and b/raindropGameCode/data/sun.png differ diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..fad863b 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,144 @@ -PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r +ArrayList rds = new ArrayList (); //make array list + +Bucket b; //make bucket catcher +Sun melt; + + +PVector mouse; //declare a Pvector mouse + +int s = 0; //declare + intialize s = score +int count = 0; //counts number of raindrops in bucket +int gamemode = 0; //variabl efor game mode -// 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 + size(1200, 800); //set size of screen + mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} + rds.add(new Raindrop(random(width), random(-height, 0))); //add raindrops to arraylist + b = new Bucket(); //bucket with diameter of 100 + melt = new Sun(); + textAlign(CENTER); //centers text } -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 + + +void draw () { + if (gamemode == 0) { //if game mode is 0 , show start screen + startscreen(); + } else if (gamemode ==1) { + playgame(); //starts game + } else if (gamemode == 2) { //if gamemmode is 2, game over screen + losescreen(); + } else if (gamemode == 3) { //if gamemode is 3, you win screen + winscreen(); } - 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 startscreen() { //startscreen fuctnion + background(0, 200, 255); //bg color + textSize(100); + fill(255); + text("Snowman", width/2, 350); //beginning info and such + textSize(20); + text("The goal of this game is to make Frosty as big as possible by collecting snowballs.", width/2, height/2); + text("Press 'SHIFT' to start", width/2, 430); +} + +void winscreen() { //winscreen function + background(0, 200, 255); //bg color + textSize(50); + text("YOU WIN", width/2, height/2); //you win + textSize(30); + text("Press 'Shift' to restart game", width/2, 450); +} + +void losescreen() { //losescreen fnction + background(0, 200, 255); //bg color + textSize(50); + text("GAME OVER", width/2, height/2); //game over + textSize(30); + text("Press 'Shift' to restart game", width/2, 450); +} + + +void playgame() { //playgame funcion + println(rds.size()); //check size of array list + + background(0, 200, 255); //bg color + + mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY + fill(255); //make scoreboard white + rect(1100, 700, 1200, 800); //draw scoreboard + fill(242, 81, 56); //score color + textSize(30); //change text size + text(s, 1150, 750); //displays score + + melt.display(); //displays sun + + for (int i = 0; i < 40; i++) { //start w/ 40 snowballs + rds.add(new Raindrop(random(width), random(-height, 0))); //add new snowballs to array list + } + + b.update(); //updates b.loc as mouse + b.display(); //display bucket + + for (int i= rds.size() - 1; i >= 0; i --) { + Raindrop r = rds.get(i); //getting item in array rds at index i + r.display(); //displays raindrop + r.fall(); //raindrops will fall + + + if (r.melts(melt)) { //if sun touches snowball + rds.remove(i); // remove snowball + } + + if (r.isInContactWith(b)) { //if a raindrop is in contact with the bucket + rds.remove(i); //remove raindrop + count++; //increase count each time bucket touches raindrop + + if (count >= 100) { + s++; //increase score + count = 0; //reset count to 0 + b.decrease(-15); //increases size of snowman + } + + if (count <= 500 && s >= 5) { //if the bucket has caught < 199 raindrops and score is > 5 + b.decrease(.55); //decreases size of snowman + } + + if (r.loc.y > height) { //if randrop hits the bottom of the screen + rds.remove(i); //remove raindrop + rds.clear(); //clears out arraylist + } + } + } + if (b.c <= 50) { //if snowman's width < 50 + gamemode = 2; //game over screen + } + + if (s == 10 || b.c > 600) { //if score gets to 10 + gamemode = 3; //you win screen } } + +void keyPressed() { + if (keyCode == SHIFT) { + if (gamemode == 0) { + gamemode = 1; //game mode changes + rds.clear(); //clear arraylist + } else if (gamemode == 2) { + gamemode = 1; //game mode changes + s = 0; //reset score + b.c = 250; //reset snowman's width + b.d = 278; //reset snowman's height + rds.clear(); //clear arraylist + } else if (gamemode == 3) { + gamemode = 1; //game mode changes + s = 0; //reset score + b.c = 250; //reset snowman's width + b.d = 278; //reset snowman's height + rds.clear(); //clear arraylist + } + } +} \ No newline at end of file diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde new file mode 100644 index 0000000..63d8e95 --- /dev/null +++ b/raindropGameCode/raindrop_class.pde @@ -0,0 +1,46 @@ +class Raindrop { //create class for raindrop + PVector loc, vel, g; //location for raindrop + int diam ; //diameter for raindrop + color c; //color for raindrop + + + Raindrop (float x, float y) { + diam = 20; //diameter is 20 + loc = new PVector(x, y); + c = color(208, 237, 247); //makes raindrop blue + vel = PVector.random2D(); //velocity with random magnitude of 1 + vel.mult(random(2, 7)); //multiplies velocity + g = new PVector (0, 0.2); //acceleration of 0,2 + } + + void display () { + fill(c); //makes raindrop blue + noStroke(); //no stroke + ellipse(loc.x, loc.y, diam, diam); //creates raindrop + } + + void fall() { + loc.add(vel); //gives raindrop velocity + vel.add(g); // add gravity + } + void reset () { + loc.y = 0; //brings raindrop back to top of screen + loc.x = random(diam/2, width - diam/2); //resets raindrop in x direction + vel.x = 0; + vel.y = 0; //this way raindrop wont speed up + } + boolean isInContactWith(Bucket b) { + if (loc.dist(b.loc) < diam/2 + b.loc.y*.3) { //if distance between mouse and snowball is less than the snowball's raidus and image's height/3 + return true; + } else { + return false; + } + } + boolean melts (Sun m) { //function melt snowballs + if (loc.dist(m.loc) < diam/2 + m.loc.x/4) { //if distance is less than the diameter of the snowball + width of image/4 + return true; //then return true + } else { //otherwise + return false; //otherwise return false + } + } +} \ No newline at end of file diff --git a/raindropGameCode/sun b/raindropGameCode/sun new file mode 100644 index 0000000..43b955e --- /dev/null +++ b/raindropGameCode/sun @@ -0,0 +1,25 @@ +class Sun { //declare new class for catching raindrops + PVector loc, vel; + PImage s; + float c, d; //control size of image + + Sun () { //create constructor + s = loadImage("sun.png"); + loc = new PVector (random(width), 100); + vel = new PVector (random(-10, 10), 0); + imageMode(CENTER); //centers image + c = 250; + d = 200; + } + + void display () { //function display bucket + image (s, loc.x, loc.y, c, d); + loc.add(vel); //give sun velocity + if (loc.x + c/2 >= width) { //if sun passes off screen + vel.mult(-1); //reverse direction + } + if (loc.x - c/2 <= 0) { + vel.mult(-1); + } + } +} diff --git a/raindropGameCode/sun.pde b/raindropGameCode/sun.pde new file mode 100644 index 0000000..f0a1ff2 --- /dev/null +++ b/raindropGameCode/sun.pde @@ -0,0 +1,25 @@ +class Sun { //declare new class for catching raindrops + PVector loc, vel; + PImage s; + float c, d; //control size of image + + Sun () { //create constructor + s = loadImage("sun.png"); + loc = new PVector (random(width), 100); + vel = new PVector (random(-10, 10), 0); + imageMode(CENTER); //centers image + c = 250; //width + d = 200; //height + } + + void display () { //function display bucket + image (s, loc.x, loc.y, c, d); + loc.add(vel); //give sun velocity + if (loc.x + c/2 >= width) { //if sun passes off right side of screen + vel.mult(-1); //reverse direction + } + if (loc.x - c/2 <= 0) { //if sun passes off left side of screen + vel.mult(-1); //reverse direction + } + } +} \ No newline at end of file