Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Sounds:
- http://soundimage.org/
- */
- import processing.sound.*;
- SoundFile file1;
- SoundFile file2;
- SoundFile file3;
- bgMusic2 music2;
- bgMusic3 music3;
- //Intro screen variables
- PImage startscreen;
- int stage;
- float x1;
- float x2;
- float y1;
- float y2;
- PImage winscreen;
- PImage endscreen;
- //Game images
- PImage happy1;
- PImage music1;
- PImage nervous2;
- PImage people2;
- PImage scared3;
- PImage zombie3;
- PImage curious4;
- PImage space4;
- PImage sad5;
- PImage yelling5;
- PImage annoyed6;
- PImage smoking6;
- PImage excited7;
- PImage games7;
- PImage amazed8;
- PImage art8;
- //board arrangement
- int[][] board = {
- {0, 1, 0, 0, 0, 0, 0, 2},
- {0, 3, 0, 0, 0, 0, 4, 0},
- {0, 0, 0, 0, 5, 0, 6, 0},
- {0, 0, 0, 6, 0, 0, 2, 0},
- {0, 0, 0, 1, 7, 0, 0, 0},
- {0, 3, 4, 0, 0, 0, 7, 0},
- {0, 0, 0, 0, 5, 0, 0, 0},
- {8, 0, 0, 0, 0, 0, 0, 8}
- };
- int gw = 80,startx, starty, curx, cury; boolean selected = false, won = false;
- color numToColor(int num) {
- if (num==1) image(happy1, gw, 0, gw, gw); image(music1, gw*3, gw*4, gw, gw);
- if (num==2) image(nervous2, gw*6, gw*3, gw, gw); image(people2, gw*7, 0, gw, gw);
- if (num==3) image(scared3, gw, gw*5, gw, gw); image(zombie3, gw, gw, gw, gw);
- if (num==4) image(curious4, gw*6, gw, gw, gw); image(space4, gw*2, gw*5, gw, gw);
- if (num==5) image(sad5, gw*4, gw*6, gw, gw); image(yelling5, gw*4, gw*2, gw, gw);
- if (num==6) image(annoyed6, gw*3, gw*3, gw, gw); image(smoking6, gw*6, gw*2, gw, gw);
- if (num==7) image(excited7, gw*6, gw*5, gw, gw); image(games7, gw*4, gw*4, gw, gw);
- if (num==8) image(amazed8, 0, gw*7, gw, gw); image(art8, gw*7, gw*7, gw, gw);
- return color(255,191,105);
- }
- void setup() { size(640,640); size(board[0].length*gw, board.length*gw); ellipseMode(CORNER);
- happy1 = loadImage("1happy.png"); music1 = loadImage("1music.jpg");
- nervous2 = loadImage("2nervous.png"); people2 = loadImage("2people.jpg");
- scared3 = loadImage("3scared.png"); zombie3 = loadImage("3zombie.jpg");
- curious4 = loadImage("4curious.png"); space4 = loadImage("4space.jpg");
- sad5 = loadImage("5sad.png"); yelling5 = loadImage("5yelling.jpg");
- annoyed6 = loadImage("6annoyed.png"); smoking6 = loadImage("6smoking.jpg");
- excited7 = loadImage("7excited.png"); games7 = loadImage("7games.jpg");
- amazed8 = loadImage("8amazed.png"); art8 = loadImage("8art.jpg");
- stage = 1;
- startscreen = loadImage("IntroScreen.jpg");
- x1 = 175;
- x2 = 442;
- y1 = 540;
- y2 = 593;
- winscreen = loadImage("WinningScreen.jpg");
- endscreen = loadImage("EndingScreen.jpg");
- //music
- file1 = new SoundFile(this, "bgMusic1.mp3");
- file1.loop();
- file1.amp(1.2);
- music2 = new bgMusic2();
- music3 = new bgMusic3();
- }
- void draw() {
- println("x :" + mouseX + "," + "y:" + mouseY);
- if(stage == 1){
- image(startscreen, 0, 0, width, height);
- if(mousePressed && x1<mouseX && mouseX<x2 && y1<mouseY && mouseY<y2 == true) {
- stage = 2;
- file1.stop();
- music2.play();
- }
- }
- if(stage==2){
- drawboard();
- if (!won) {
- if (mousePressed && !selected) {
- //if you clicked and haven't selected yet
- startx = int(mouseX / gw); starty = int(mouseY / gw);
- curx=startx; cury=starty;
- //current x & y pos
- if (board[starty][startx] > 0) selected = true;
- //if you select one of the circles then something is selected
- }
- if (mousePressed==false && selected==true) {
- //click & let go
- selected = false;
- int endx = -1, endy = -1;
- for (int j=0;j<board.length;j++) {
- for (int i=0;i<board[j].length;i++) {
- if ( !(i==startx && j==starty) && board[j][i] == board[starty][startx]) {
- endx = i; endy = j;
- //if you let go on something it has to be the same number to count
- }
- }
- }
- if ( (curx == endx && cury == endy + 1) ||
- (curx == endx && cury == endy - 1) ||
- (curx == endx + 1 && cury == endy) ||
- (curx == endx - 1 && cury == endy)) checkwin();
- else {
- for (int j=0;j<board.length;j++) {
- for(int i=0;i<board[j].length;i++) if(board[j][i]==-board[starty][startx]) board[j][i]=0;
- }
- }
- }
- if (mousePressed==true && selected==true) {
- //draw pipes
- int x = int(mouseX/gw), y = int(mouseY/gw);
- if (x>=0 && y >= 0 && y<board.length&&x<board[0].length && board[y][x]==0) {
- if ( (x == curx + 1 && y == cury) ||
- (x==curx-1&&y==cury) || (x == curx && y == cury + 1) || (x == curx && y == cury - 1)) {
- board[y][x] = -board[starty][startx]; //negative value is pipe
- curx = x; cury = y;
- }
- }
- }
- }
- else {
- rect(0,0,width,height);
- image(winscreen, 0, 0, width, height);
- stage = 3;
- music2.stop();
- music3.play();
- }
- }//stage 2
- if (stage == 3) {
- if (mousePressed && 530<mouseX && mouseX<595 && 570<mouseY && mouseY<600 == true){
- stage = 4;
- }
- }
- if (stage == 4) {
- image(endscreen, 0, 0, width, height);
- }
- }
- void drawboard() {
- for (int j=0;j<board.length;j++) {
- for (int i=0;i<board[j].length;i++) {
- int x = i*gw,y = j*gw;
- fill(113,165,200); stroke(100); rect(x, y, gw, gw);
- fill(numToColor(board[j][i]));
- //draw circles
- //if (board[j][i]>0) ellipse(x+20, y+20, gw/2, gw/2);
- if (board[j][i]<0) { //pipes are less than 0
- boolean left = false, right = false, above = false, below = false;
- if( i > 0 && abs(board[j][i])==abs(board[j][i-1])) left = true;
- if( j > 0 && abs(board[j][i])==abs(board[j-1][i])) above = true;
- if( i < board.length-1 && abs(board[j][i])==abs(board[j][i+1])) right = true;
- if( j < board.length-1 && abs(board[j][i])==abs(board[j+1][i])) below = true;
- fill(numToColor(-board[j][i]));
- noStroke();
- rect(x+gw/4, y+gw/4, gw/2, gw/2);
- if(above && below) rect(x+gw/4, y, gw/2, gw);
- if(left && right) rect(x, y+gw/4, gw, gw/2);
- if(above && left) { rect(x, y+gw/4, gw/2, gw/2); rect(x+gw/4, y, gw/2, gw/2); }
- if(above && right) {rect(x+gw/2, y+gw/4, gw/2, gw/2); rect(x+gw/4, y, gw/2, gw/2); }
- if(below && left) { rect(x, y+gw/4, gw/2, gw/2); rect(x+gw/4, y+gw/2, gw/2, gw/2); }
- 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); }
- }
- }
- }
- }
- void checkwin() {
- won = true;
- for (int j=0;j<board.length;j++) for (int i=0;i<board[j].length;i++) {
- boolean foundpipe = false;
- if (board[j][i]>0) {
- for (int m=0;m<board.length;m++) for (int k=0;k<board[m].length;k++)
- if (board[m][k]==-board[j][i]) foundpipe = true;
- if (foundpipe ==false) won = false;
- }
- }
- }
- class bgMusic2 {
- void play() {
- file2 = new SoundFile(flow.this, "bgMusic2.mp3");
- file2.play();
- }
- void stop() {
- file2.stop();
- }
- }
- class bgMusic3 {
- void play() {
- file3 = new SoundFile(flow.this, "bgMusic3.mp3");
- file3.play();
- }
- void stop() {
- file3.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment