Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Victoria Kelly
- //Spongebob Game
- //Collect all the Jellyfish Jelly for the krabby patties
- //Revised in class 3/29/17
- Spongebob spongebob; // "catcher"
- Timer timer; // timer
- Jelly[] jelly; // array of jelly drops
- int score = 0; //keeping score of the game
- int totalDrops = 0; // totalDrops
- PImage img; //spongebob
- PImage img2; //jellfish fields
- PImage img3; //start screen picture
- int stage = 0; //start screen
- PFont myFont; //start screen spongebob logo font
- color bestColor; //reset button
- int z;
- int state;
- boolean b;
- import processing.sound.*; //spongebobs laugh & background music
- SoundFile file;
- void setup() {
- size(981,698);
- String[] fontList = PFont.list(); //font for start screen
- printArray(fontList);
- myFont = createFont("Some Time Later", 32);
- fill(255);
- textFont(myFont);
- textAlign(CENTER, CENTER);
- text("Help Spongebob collect the jellyfish jelly!", width/2, height/2);
- spongebob = new Spongebob(50); // radius of the "catcher"
- jelly = new Jelly[2000]; // spots in the array
- timer = new Timer(500); // timer that goes off every "blank" milliseconds
- timer.start(); // start timer
- // images
- img = loadImage("spongebob_fishing.png");
- img2 = loadImage("jellyfish_fields.jpg");
- // background music
- file = new SoundFile(this, "Spongebob-Jellyfish Jam Theme Song.mp3");
- file.loop();
- reset();
- }
- void reset(){ // RESET BUTTON
- bestColor = color(0,128,0);
- z = 90;
- state = 1;
- b = false;
- }
- void draw() {
- background(img2); //jellyfish fields
- noCursor(); //spongebob becomes cursor
- text(score,900,600); //score keep
- // catcher location
- spongebob.setLocation(mouseX, mouseY);
- // display catcher
- spongebob.display();
- // Check timer
- if (timer.isFinished()) {
- // Deal with jelly drops
- // Initialize one drop
- jelly[totalDrops] = new Jelly();
- // Increment totalDrops
- totalDrops ++ ;
- // If we hit the end of the array
- if (totalDrops >= jelly.length) {
- totalDrops = 0; // Start over
- }
- timer.start();
- }
- if (stage == 0){ //start screen
- startScreen();
- }
- if(b){ //RESET BUTTON
- background(87,196,201);
- fill(255);
- text("Press ENTER to start!", width/2, height/2);
- }
- // Move and display all jelly drops
- for (int i = 0; i < totalDrops; i++ ) {
- jelly[i].move();
- jelly[i].display();
- if (spongebob.intersect(jelly[i])) {
- jelly[i].caught();
- score++; //score goes up when intersected
- }
- }
- fill(184,186,198);
- rect(0,800,1500,297);
- }
- class Spongebob { //spongebobs location, moving with mouse
- float r; //radius
- float x, y; //location
- Spongebob(float tempR) {
- r = tempR;
- x = 0;
- y = 0;
- }
- void setLocation(float tempX, float tempY) {
- x = tempX;
- y = tempY;
- }
- void display() { //spongebob
- image(img,mouseX-240,mouseY-40);
- }
- //if spongebob intersects with a jelly drop it disappears, otherwise false
- boolean intersect(Jelly j) {
- float distance = dist(x,y,j.x,j.y);
- if (distance < r + j.r) {
- return true;
- } else {
- return false;
- }
- }
- }
- class Jelly {
- float x, y; // Variable for location of jelly drop
- float speed; // Speed of jelly drops
- color c;
- float r; // radius of jelly drops
- Jelly() {
- r = 12; //all drops are the same size
- x = random(width); //start with random x location
- y = -r*4; //start a little above the window
- speed = random(1,5); // pick a random speed
- c = color(50,100,150);
- }
- //Move the jelly drops down the screen
- void move() {
- y +=speed; //increment speed
- }
- //display the drops
- void display() {
- noStroke();
- fill(250,96,204);
- for (int i = 2; i < r; i++) {
- ellipse(x, y+i*4, i*2, i*2);
- }
- }
- //if the drop is caught
- void caught() {
- speed = 0; //stop it from moving by setting speed equal to zero
- y = -1000; //set the location to somewhere way off-screen
- }
- }
- class Timer {
- int savedTime; //when timer started
- int totalTime; //how long timer should last
- Timer(int tempTotalTime) {
- totalTime = tempTotalTime;
- }
- //starting the timer
- void start() {
- savedTime = millis();
- }
- boolean isFinished() {
- //check out how much time has passed
- int passedTime = millis()- savedTime;
- if (passedTime > totalTime) {
- return true;
- } else {
- return false;
- }
- }
- }
- void startScreen() { // midterm project code
- fill(255);
- background(87,196,201);
- textAlign(CENTER, CENTER);
- //textFont(Some Time Later);
- text("Help Spongebob collect the jellyfish jelly!", width/2, height/2);
- }
- void keyPressed() {
- if (key == RETURN || key == ENTER) {
- println("Hit Return stage 0");
- if (stage == 0){ // if on the start screen
- stage = 1; // advance to the next stage
- } else { // otherwise do nothing
- }
- }
- //RESET
- else if (key == ENTER) {
- stage = 0;
- }
- if(b){
- reset();
- } else {
- b = true;
- }
- //if (score == 50) { //*******RESET GAME ONCE SCORE HITS 50
- //reset();
- //}
- }
- void mousePressed() {
- // Load a soundfile from the /data folder of the sketch and play it back
- file = new SoundFile(this, "Spongebob Laugh- Sound Effect.mp3");
- file.play();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement