cherrybearr

Get to Know Me Game

May 11th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.04 KB | None | 0 0
  1. /*
  2. Sounds:
  3. http://soundimage.org/
  4. */
  5.  
  6. import processing.sound.*;
  7.  
  8. SoundFile file1;
  9. SoundFile file2;
  10. SoundFile file3;
  11.  
  12. bgMusic2 music2;
  13. bgMusic3 music3;
  14.  
  15. //Intro screen variables
  16. PImage startscreen;
  17. int stage;
  18. float x1;
  19. float x2;
  20. float y1;
  21. float y2;
  22.  
  23. PImage winscreen;
  24.  
  25. PImage endscreen;
  26.  
  27. //Game images
  28. PImage happy1;
  29. PImage music1;
  30. PImage nervous2;
  31. PImage people2;
  32. PImage scared3;
  33. PImage zombie3;
  34. PImage curious4;
  35. PImage space4;
  36. PImage sad5;
  37. PImage yelling5;
  38. PImage annoyed6;
  39. PImage smoking6;
  40. PImage excited7;
  41. PImage games7;
  42. PImage amazed8;
  43. PImage art8;
  44.  
  45. //board arrangement
  46. int[][] board = {
  47.   {0, 1, 0, 0, 0, 0, 0, 2},
  48.   {0, 3, 0, 0, 0, 0, 4, 0},
  49.   {0, 0, 0, 0, 5, 0, 6, 0},
  50.   {0, 0, 0, 6, 0, 0, 2, 0},
  51.   {0, 0, 0, 1, 7, 0, 0, 0},
  52.   {0, 3, 4, 0, 0, 0, 7, 0},
  53.   {0, 0, 0, 0, 5, 0, 0, 0},
  54.   {8, 0, 0, 0, 0, 0, 0, 8}
  55. };
  56. int gw = 80,startx, starty, curx, cury; boolean selected = false, won = false;
  57. color numToColor(int num) {
  58.   if (num==1) image(happy1, gw, 0, gw, gw); image(music1, gw*3, gw*4, gw, gw);
  59.   if (num==2) image(nervous2, gw*6, gw*3, gw, gw); image(people2, gw*7, 0, gw, gw);
  60.   if (num==3) image(scared3, gw, gw*5, gw, gw); image(zombie3, gw, gw, gw, gw);
  61.   if (num==4) image(curious4, gw*6, gw, gw, gw); image(space4, gw*2, gw*5, gw, gw);
  62.   if (num==5) image(sad5, gw*4, gw*6, gw, gw); image(yelling5, gw*4, gw*2, gw, gw);
  63.   if (num==6) image(annoyed6, gw*3, gw*3, gw, gw); image(smoking6, gw*6, gw*2, gw, gw);
  64.   if (num==7) image(excited7, gw*6, gw*5, gw, gw); image(games7, gw*4, gw*4, gw, gw);
  65.   if (num==8) image(amazed8, 0, gw*7, gw, gw); image(art8, gw*7, gw*7, gw, gw);
  66.   return color(255,191,105);
  67. }
  68. void setup() { size(640,640); size(board[0].length*gw, board.length*gw); ellipseMode(CORNER);
  69.   happy1 = loadImage("1happy.png"); music1 = loadImage("1music.jpg");
  70.   nervous2 = loadImage("2nervous.png"); people2 = loadImage("2people.jpg");
  71.   scared3 = loadImage("3scared.png"); zombie3 = loadImage("3zombie.jpg");
  72.   curious4 = loadImage("4curious.png"); space4 = loadImage("4space.jpg");
  73.   sad5 = loadImage("5sad.png"); yelling5 = loadImage("5yelling.jpg");
  74.   annoyed6 = loadImage("6annoyed.png"); smoking6 = loadImage("6smoking.jpg");
  75.   excited7 = loadImage("7excited.png"); games7 = loadImage("7games.jpg");
  76.   amazed8 = loadImage("8amazed.png"); art8 = loadImage("8art.jpg");
  77.  
  78.   stage = 1;
  79.   startscreen = loadImage("IntroScreen.jpg");
  80.   x1 = 175;
  81.   x2 = 442;
  82.   y1 = 540;
  83.   y2 = 593;
  84.  
  85.   winscreen = loadImage("WinningScreen.jpg");
  86.  
  87.   endscreen = loadImage("EndingScreen.jpg");
  88.  
  89.   //music
  90.   file1 = new SoundFile(this, "bgMusic1.mp3");
  91.   file1.loop();
  92.   file1.amp(1.2);
  93.  
  94.   music2 = new bgMusic2();
  95.   music3 = new bgMusic3();
  96.  
  97. }
  98.  
  99. void draw() {
  100.   println("x :" + mouseX + "," + "y:" + mouseY);
  101.  
  102.   if(stage == 1){
  103.     image(startscreen, 0, 0, width, height);
  104.     if(mousePressed && x1<mouseX && mouseX<x2 && y1<mouseY && mouseY<y2 == true) {
  105.       stage = 2;
  106.       file1.stop();
  107.       music2.play();
  108.     }
  109.  
  110.   }
  111.  
  112. if(stage==2){
  113.   drawboard();
  114.   if (!won) {
  115.     if (mousePressed && !selected) {
  116.       //if you clicked and haven't selected yet
  117.       startx = int(mouseX / gw); starty = int(mouseY / gw);
  118.       curx=startx; cury=starty;
  119.       //current x & y pos
  120.       if (board[starty][startx] > 0) selected = true;
  121.       //if you select one of the circles then something is selected
  122.     }
  123.     if (mousePressed==false && selected==true) {
  124.       //click & let go
  125.       selected = false;
  126.       int endx = -1, endy = -1;
  127.       for (int j=0;j<board.length;j++) {
  128.         for (int i=0;i<board[j].length;i++) {
  129.           if ( !(i==startx && j==starty) && board[j][i] == board[starty][startx]) {
  130.             endx = i; endy = j;
  131.             //if you let go on something it has to be the same number to count
  132.           }
  133.         }
  134.       }
  135.       if (  (curx == endx && cury == endy + 1) ||
  136.         (curx == endx && cury == endy - 1) ||
  137.         (curx == endx + 1 && cury == endy) ||
  138.         (curx == endx - 1 && cury == endy)) checkwin();
  139.       else {
  140.         for (int j=0;j<board.length;j++) {
  141.           for(int i=0;i<board[j].length;i++) if(board[j][i]==-board[starty][startx]) board[j][i]=0;
  142.         }
  143.       }
  144.     }
  145.     if (mousePressed==true && selected==true) {
  146.       //draw pipes
  147.       int x = int(mouseX/gw), y = int(mouseY/gw);
  148.       if (x>=0 && y >= 0 && y<board.length&&x<board[0].length && board[y][x]==0) {
  149.         if (  (x == curx + 1 && y == cury) ||
  150.           (x==curx-1&&y==cury) || (x == curx && y == cury + 1) || (x == curx && y == cury - 1)) {
  151.           board[y][x] = -board[starty][startx]; //negative value is pipe
  152.           curx = x; cury = y;
  153.         }
  154.       }
  155.     }
  156.   }
  157.   else {
  158.     rect(0,0,width,height);
  159.     image(winscreen, 0, 0, width, height);
  160.     stage = 3;
  161.     music2.stop();
  162.     music3.play();
  163.     }
  164.   }//stage 2
  165.  
  166.   if (stage == 3) {
  167.       if (mousePressed && 530<mouseX && mouseX<595 && 570<mouseY && mouseY<600 == true){
  168.       stage = 4;
  169.       }
  170.   }
  171.  
  172. if (stage == 4) {
  173.   image(endscreen, 0, 0, width, height);
  174. }
  175. }
  176.  
  177. void drawboard() {
  178.   for (int j=0;j<board.length;j++) {
  179.     for (int i=0;i<board[j].length;i++) {
  180.       int x = i*gw,y = j*gw;
  181.       fill(113,165,200); stroke(100); rect(x, y, gw, gw);
  182.       fill(numToColor(board[j][i]));
  183.       //draw circles
  184.       //if (board[j][i]>0) ellipse(x+20, y+20, gw/2, gw/2);
  185.       if (board[j][i]<0) { //pipes are less than 0
  186.         boolean left = false, right = false, above = false, below = false;
  187.         if( i > 0 && abs(board[j][i])==abs(board[j][i-1])) left = true;
  188.         if( j > 0 && abs(board[j][i])==abs(board[j-1][i])) above = true;
  189.         if( i < board.length-1 && abs(board[j][i])==abs(board[j][i+1])) right = true;
  190.         if( j < board.length-1 && abs(board[j][i])==abs(board[j+1][i])) below = true;
  191.         fill(numToColor(-board[j][i]));
  192.         noStroke();
  193.         rect(x+gw/4, y+gw/4, gw/2, gw/2);
  194.         if(above && below) rect(x+gw/4, y, gw/2, gw);
  195.         if(left && right) rect(x, y+gw/4, gw, gw/2);
  196.         if(above && left) { rect(x, y+gw/4, gw/2, gw/2); rect(x+gw/4, y, gw/2, gw/2); }
  197.         if(above && right) {rect(x+gw/2, y+gw/4, gw/2, gw/2); rect(x+gw/4, y, gw/2, gw/2); }
  198.         if(below && left) { rect(x, y+gw/4, gw/2, gw/2); rect(x+gw/4, y+gw/2, gw/2, gw/2); }
  199.         if(below && right) {rect(x+gw/2, y+gw/4, gw/2, gw/2); rect(x+gw/4, y+gw/2, gw/2, gw/2); }
  200.       }
  201.     }
  202.   }
  203. }
  204. void checkwin() {
  205.   won = true;
  206.   for (int j=0;j<board.length;j++) for (int i=0;i<board[j].length;i++) {
  207.     boolean foundpipe = false;
  208.     if (board[j][i]>0) {
  209.       for (int m=0;m<board.length;m++) for (int k=0;k<board[m].length;k++)
  210.         if (board[m][k]==-board[j][i]) foundpipe = true;
  211.       if (foundpipe ==false) won = false;
  212.     }
  213.   }
  214. }
  215.  
  216. class bgMusic2 {
  217.   void play() {
  218.     file2 = new SoundFile(flow.this, "bgMusic2.mp3");
  219.     file2.play();
  220.   }
  221.   void stop() {
  222.     file2.stop();
  223.   }
  224. }
  225. class bgMusic3 {
  226.   void play() {
  227.     file3 = new SoundFile(flow.this, "bgMusic3.mp3");
  228.     file3.play();
  229.   }
  230.   void stop() {
  231.     file3.stop();
  232.   }
  233. }
Advertisement
Add Comment
Please, Sign In to add comment