Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. //Victoria Kelly
  2. //Spongebob Game
  3. //Collect all the Jellyfish Jelly for the krabby patties
  4. //Revised in class 3/29/17
  5.  
  6. Spongebob spongebob; // "catcher"
  7. Timer timer; // timer
  8. Jelly[] jelly; // array of jelly drops
  9.  
  10. int score = 0; //keeping score of the game
  11.  
  12. int totalDrops = 0; // totalDrops
  13.  
  14. PImage img; //spongebob
  15. PImage img2; //jellfish fields
  16. PImage img3; //start screen picture
  17.  
  18. int stage = 0; //start screen
  19. PFont myFont; //start screen spongebob logo font
  20.  
  21. color bestColor; //reset button
  22. int z;
  23. int state;
  24. boolean b;
  25.  
  26.  
  27. import processing.sound.*; //spongebobs laugh & background music
  28. SoundFile file;
  29.  
  30. void setup() {
  31. size(981,698);
  32.  
  33. String[] fontList = PFont.list(); //font for start screen
  34. printArray(fontList);
  35. myFont = createFont("Some Time Later", 32);
  36. fill(255);
  37. textFont(myFont);
  38. textAlign(CENTER, CENTER);
  39. text("Help Spongebob collect the jellyfish jelly!", width/2, height/2);
  40.  
  41. spongebob = new Spongebob(50); // radius of the "catcher"
  42. jelly = new Jelly[2000]; // spots in the array
  43. timer = new Timer(500); // timer that goes off every "blank" milliseconds
  44. timer.start(); // start timer
  45.  
  46. // images
  47. img = loadImage("spongebob_fishing.png");
  48. img2 = loadImage("jellyfish_fields.jpg");
  49.  
  50. // background music
  51. file = new SoundFile(this, "Spongebob-Jellyfish Jam Theme Song.mp3");
  52. file.loop();
  53.  
  54. reset();
  55. }
  56.  
  57. void reset(){ // RESET BUTTON
  58. bestColor = color(0,128,0);
  59. z = 90;
  60. state = 1;
  61. b = false;
  62. }
  63. void draw() {
  64. background(img2); //jellyfish fields
  65.  
  66. noCursor(); //spongebob becomes cursor
  67.  
  68. text(score,900,600); //score keep
  69.  
  70.  
  71. // catcher location
  72. spongebob.setLocation(mouseX, mouseY);
  73. // display catcher
  74. spongebob.display();
  75.  
  76. // Check timer
  77. if (timer.isFinished()) {
  78. // Deal with jelly drops
  79. // Initialize one drop
  80. jelly[totalDrops] = new Jelly();
  81. // Increment totalDrops
  82. totalDrops ++ ;
  83. // If we hit the end of the array
  84. if (totalDrops >= jelly.length) {
  85. totalDrops = 0; // Start over
  86. }
  87. timer.start();
  88. }
  89.  
  90. if (stage == 0){ //start screen
  91. startScreen();
  92. }
  93.  
  94. if(b){ //RESET BUTTON
  95. background(87,196,201);
  96. fill(255);
  97. text("Press ENTER to start!", width/2, height/2);
  98. }
  99. // Move and display all jelly drops
  100. for (int i = 0; i < totalDrops; i++ ) {
  101. jelly[i].move();
  102. jelly[i].display();
  103. if (spongebob.intersect(jelly[i])) {
  104. jelly[i].caught();
  105. score++; //score goes up when intersected
  106. }
  107. }
  108. fill(184,186,198);
  109. rect(0,800,1500,297);
  110. }
  111. class Spongebob { //spongebobs location, moving with mouse
  112. float r; //radius
  113. float x, y; //location
  114.  
  115. Spongebob(float tempR) {
  116. r = tempR;
  117. x = 0;
  118. y = 0;
  119. }
  120.  
  121. void setLocation(float tempX, float tempY) {
  122. x = tempX;
  123. y = tempY;
  124. }
  125.  
  126. void display() { //spongebob
  127. image(img,mouseX-240,mouseY-40);
  128. }
  129.  
  130. //if spongebob intersects with a jelly drop it disappears, otherwise false
  131. boolean intersect(Jelly j) {
  132. float distance = dist(x,y,j.x,j.y);
  133. if (distance < r + j.r) {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. }
  139. }
  140. class Jelly {
  141. float x, y; // Variable for location of jelly drop
  142. float speed; // Speed of jelly drops
  143. color c;
  144. float r; // radius of jelly drops
  145.  
  146. Jelly() {
  147. r = 12; //all drops are the same size
  148. x = random(width); //start with random x location
  149. y = -r*4; //start a little above the window
  150. speed = random(1,5); // pick a random speed
  151. c = color(50,100,150);
  152. }
  153.  
  154. //Move the jelly drops down the screen
  155. void move() {
  156. y +=speed; //increment speed
  157. }
  158. //display the drops
  159. void display() {
  160.  
  161. noStroke();
  162. fill(250,96,204);
  163. for (int i = 2; i < r; i++) {
  164. ellipse(x, y+i*4, i*2, i*2);
  165.  
  166. }
  167. }
  168.  
  169. //if the drop is caught
  170. void caught() {
  171. speed = 0; //stop it from moving by setting speed equal to zero
  172. y = -1000; //set the location to somewhere way off-screen
  173. }
  174. }
  175.  
  176. class Timer {
  177.  
  178. int savedTime; //when timer started
  179. int totalTime; //how long timer should last
  180.  
  181. Timer(int tempTotalTime) {
  182. totalTime = tempTotalTime;
  183. }
  184.  
  185. //starting the timer
  186. void start() {
  187. savedTime = millis();
  188. }
  189.  
  190. boolean isFinished() {
  191. //check out how much time has passed
  192. int passedTime = millis()- savedTime;
  193. if (passedTime > totalTime) {
  194. return true;
  195. } else {
  196. return false;
  197. }
  198. }
  199. }
  200. void startScreen() { // midterm project code
  201. fill(255);
  202. background(87,196,201);
  203. textAlign(CENTER, CENTER);
  204. //textFont(Some Time Later);
  205. text("Help Spongebob collect the jellyfish jelly!", width/2, height/2);
  206.  
  207. }
  208.  
  209. void keyPressed() {
  210.  
  211. if (key == RETURN || key == ENTER) {
  212. println("Hit Return stage 0");
  213. if (stage == 0){ // if on the start screen
  214. stage = 1; // advance to the next stage
  215. } else { // otherwise do nothing
  216. }
  217. }
  218. //RESET
  219.  
  220. else if (key == ENTER) {
  221. stage = 0;
  222. }
  223. if(b){
  224. reset();
  225. } else {
  226. b = true;
  227. }
  228. //if (score == 50) { //*******RESET GAME ONCE SCORE HITS 50
  229. //reset();
  230. //}
  231. }
  232. void mousePressed() {
  233. // Load a soundfile from the /data folder of the sketch and play it back
  234. file = new SoundFile(this, "Spongebob Laugh- Sound Effect.mp3");
  235. file.play();
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement