diff --git a/raindropGameCode/Catcher.pde b/raindropGameCode/Catcher.pde new file mode 100644 index 0000000..f12d221 --- /dev/null +++ b/raindropGameCode/Catcher.pde @@ -0,0 +1,19 @@ +class Catcher { //creating the catcher + PVector loc; + int diam; + PImage catcher; //the catcher will be an image + + Catcher (int tdiam) { //creating the catcher + loc=new PVector() ; //location of the catcher is a + diam=tdiam; + catcher = loadImage("lantern.png"); + } + + void display() { + image(catcher, loc.x, loc.y); //image as catcher + } + + void update() { + loc.set(mouseX-25, mouseY-25); //where the raindrops will hit the catcher + } +} \ No newline at end of file diff --git a/raindropGameCode/data/ball.jpg b/raindropGameCode/data/ball.jpg new file mode 100644 index 0000000..ee0e5ac Binary files /dev/null and b/raindropGameCode/data/ball.jpg differ diff --git a/raindropGameCode/data/court.jpg b/raindropGameCode/data/court.jpg new file mode 100644 index 0000000..26d39e1 Binary files /dev/null and b/raindropGameCode/data/court.jpg differ diff --git a/raindropGameCode/data/forest.jpg b/raindropGameCode/data/forest.jpg new file mode 100644 index 0000000..9ab1453 Binary files /dev/null and b/raindropGameCode/data/forest.jpg differ diff --git a/raindropGameCode/data/hoop.jpg b/raindropGameCode/data/hoop.jpg new file mode 100644 index 0000000..7a56f39 Binary files /dev/null and b/raindropGameCode/data/hoop.jpg differ diff --git a/raindropGameCode/data/lantern.png b/raindropGameCode/data/lantern.png new file mode 100644 index 0000000..7ce271f Binary files /dev/null and b/raindropGameCode/data/lantern.png differ diff --git a/raindropGameCode/data/nike.jpg b/raindropGameCode/data/nike.jpg new file mode 100644 index 0000000..85676a0 Binary files /dev/null and b/raindropGameCode/data/nike.jpg differ diff --git a/raindropGameCode/data/not.jpg b/raindropGameCode/data/not.jpg new file mode 100644 index 0000000..5498dd5 Binary files /dev/null and b/raindropGameCode/data/not.jpg differ diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..f56f9ba 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,26 +1,83 @@ +PImage not; PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r - +ArrayList raindrops = new ArrayList (); +Catcher ca; +int score; +float start; +float diam; +PImage forest; // 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 - +//declaring variables 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 + start=1; + size(1200, 800); // sets size of canvas + mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} + ca=new Catcher(100); //initialize the cathcher + diam=50; + forest=loadImage("forest.jpg"); } + void draw() { + if (start == 1) { //initial screen + background(0); + textSize(32); //text size + fill(240, 53, 0); + text("Catch the Light!", width/2-150, 350); //text will be "Play Pong" + text("Press any Key to Start", width/2-175, height/2); //text will be "Press any Key" + if (keyPressed == true) { //if any key is pressed + start = 2; //the game will start + } + } + + if (start ==2) { //when the game starts + + game(); //this will be the game that starts and the code for the game is below + } +} +void game() { //code for the actual game + background(0); + raindrops.add(new Raindrop(random(width), 0)); //initialize the image + 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 + fill(255, 233, 101); + ellipse(mouseX+20, mouseY+60, diam, diam); + + for (int e =raindrops.size()-1; e>=0; e--) { + Raindrop ball = raindrops.get(e); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + ball.display(); //display the raindrop + ball.fall(); //make the balls come down + if (ball.isInContactWith(ca)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + ball.reset(); //if it is, reset the raindrop + score +=1; + diam += 0.3; + } + if (ball.loc.y > height + ball.diam/2) { //check to see if the raindrop goes below the bottom of the screen + ball.reset(); //if it does, reset the raindrop + score-=1; // add one to the score + } } - 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 + ca.display(); //display the catcher + ca.update(); //update the catcher + textSize(32); + fill(252, 250, 254); + text(score, width/2, 700); + if (score>1) { //when the score is more than 275 aka player has missed more than 275 balls + gameover(); //the player wins the game and it ends the game } } + +void gameover() { //code to end game + not(); //backrgound for final screen + textSize(48); + fill(255); + text("You Win!", width/2-100, height/2); +} + + +void not() { //image function for end of game background + background(0); +} \ No newline at end of file diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde new file mode 100644 index 0000000..2f4e694 --- /dev/null +++ b/raindropGameCode/raindrop_class.pde @@ -0,0 +1,38 @@ +class Raindrop { + PVector loc, vel, acc; + float diam; + color c; + + Raindrop(float x, float y) { + diam = random(20, 50); + loc = new PVector(random(diam, width-diam), 0); + vel= new PVector(0, random(15)); + c = color(255, 233, 101); + } + + //after declaring fields and setting up constructors, you can define your methods + void display() { + fill(c); + noStroke(); + for (int i = 2; i < diam/2; i++ ) { + ellipse(loc.x, loc.y + i*4, i*2, i*2); + } + } + void fall() { + vel.limit(5); + loc.add(vel); + } + + void reset() { + loc.y=0; + loc.add(vel); + } + + boolean isInContactWith(Catcher thing) { + if (ca.loc.dist(loc) < ca.diam/2 + diam/2 ) { + return true; //if it hits any part of the catcher reset the raindrop + } else { + return false; + } + } +} \ No newline at end of file