diff --git a/raindropGameCode/BUCKET.png b/raindropGameCode/BUCKET.png new file mode 100644 index 0000000..7e5ab0a Binary files /dev/null and b/raindropGameCode/BUCKET.png differ diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde new file mode 100644 index 0000000..4361d16 --- /dev/null +++ b/raindropGameCode/Catcher.pde @@ -0,0 +1,35 @@ +class Catcher {//declare the bucket + float diam; // radius + color co; // color + PVector loc; // location + + Catcher(float tempD) {//intialize/call + diam = tempD; + co = color(128, 128, 128); + loc = new PVector(0,0); + } + + void setLocation(PVector m) {//where the bucket will temporarily be + loc.set(m.x,m.y); + } + + void display() {//function for bucket appearance + noStroke(); + fill(co); + ellipse(loc.x,loc.y, diam*4, diam*4); + } + + // A function that returns true or false based on + // if the catcher intersects a raindrop + boolean intersect(Raindrop d) { + // Calculate distance + float distance = loc.dist(d.loc); + + // Compare the length of the bucket to the raindrop + if (distance < diam + d.diam) { + return true; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/raindropGameCode/Raindrop.pde b/raindropGameCode/Raindrop.pde new file mode 100644 index 0000000..4d2d0f9 --- /dev/null +++ b/raindropGameCode/Raindrop.pde @@ -0,0 +1,35 @@ +class Raindrop {//declare Raindrop + PVector loc, vel, acc;//variable for length, speed, color + float diam; + color co; + + + Raindrop() {//call functionality and intialize + diam=20; + loc=new PVector(random(0, width), 0); + vel=PVector.random2D(); + acc=new PVector(0, .1); + co= color(204, 255, 255); + } + void display() {//function so raindrops appear + fill(co); + noStroke(); + triangle(loc.x-diam/2, loc.y, loc.x, loc.y-40, loc.x+diam/2, loc.y); + ellipse(loc.x, loc.y, diam, diam); + } + boolean isInContactWith() {//raindrop is in contact with the mouse, does something + if (loc.y>height+diam/2) { + return true; + } else { + return false;//disappears + } + } + void fall() {//how the raindrops fall + vel.add(acc); + loc.add(vel); + } + void reset() {//when its over the screen, disappears + loc.y=0; + vel.y=0; + } +} \ No newline at end of file diff --git a/raindropGameCode/Timer.pde b/raindropGameCode/Timer.pde new file mode 100644 index 0000000..d5cb319 --- /dev/null +++ b/raindropGameCode/Timer.pde @@ -0,0 +1,28 @@ +class Timer {//declare the timer + int s; + int m; + + Timer() {//initialize + s=0; + m=0; + } + + void display() {//call functionality + fill(153, 204, 0); + textAlign(CENTER);//how the text will look like + textSize(50); + delay(1000); + if (s<=59) {//before it reaches 60 seconds, only the right hand side will change + text(m+":"+s, width/2, height/2); + s=s+1; + } else {//the left side will now change after 60 seconds + m=m+1; + s=0; + text(m+";"+s, width/2, height/2); + } + } + void reset(){//function so time resets when game over + m=0; + s=0; + } +} \ No newline at end of file diff --git a/raindropGameCode/background.jpg b/raindropGameCode/background.jpg new file mode 100644 index 0000000..998a7cd Binary files /dev/null and b/raindropGameCode/background.jpg differ diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..39216d4 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,75 @@ PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r - +ArrayList r= new ArrayList(); //declare a new ArrayList called r for the raindrop +Catcher C;//declare Bucket +Timer timer;//declare Timer +PImage background; // 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 +int mode=0;//0 is intro, 1 is normal play, 2 means game has ended + +void setup() {//run settings once -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 + mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} + //Initialize r. The parameters used are the initial x and y positions + C= new Catcher(20);//initalize catcher + timer= new Timer();//initialize timer + background= loadImage("background.jpg"); + for ( int i=0; i<5; i++) {//for loop and arraylist. + r.add(new Raindrop ()); + } } +void draw() {//run settings in loop + if (mode==0) {//intro + fill(0, 255, 0); + imageMode(CENTER);//background + image(background, width/2, height/2); + textSize(20); + textAlign(CENTER); + fill(255); + text("WELCOME TO THE DROP", width/2, height/2-50); + text("YOU ARE TIMED. CATCH ALL THE RAINDROPS OR ELSE.", width/2, height/2+25); + text("PRESS ENTER TO START", width/2, height/2+50); + if (keyPressed==true) { + //if(keyCode==ENTER) + mode=1; + } + } -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 (mode==1) {//normal play + background(0); + mouse.set(mouseX, mouseY);//set value of mouse as mouseX,mouseY + C.setLocation(mouse);//call functions for catcher and raindrop + C.display(); + timer.display();//call function for timer + for (int i=0; i height + rd.diam/2) { //check to see if the raindrop goes below the bottom of the screen + // r.remove(i); //if it does, reset the raindrop + //} + if (rd.loc.y>height) { + mode=2; + } + } } - 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 (mode==2) {//game over screen + background(0); + fill(0, 255, 0); + textSize(20); + textAlign(CENTER); + text("GAME", width/2, height/2); + text("OVER", width/2, height/2+75); + text("PRESS ENTER TO PLAY AGAIN", width/2, height/2+150); + timer.reset(); + if ( keyPressed==true) { + //if(keyCode==ENTER) + mode=0;//returns to the beginning screen and timer is reset + } } -} +} \ No newline at end of file