2014年6月29日 星期日

第十七周進度

期末作品進度

最後的製作階段

1.改變背景與音樂、音效
2.把干擾怪物鬼改成兩隻
3.加上計時星星,若星星下墜到地面便開啟失敗畫面
4.將遊戲製作成Leap Motion體感偵測的遊戲進行方式
   用手比石頭 : 跳躍
   用手比一或二 : 左走
   用手比三或四 : 右走

完成遊戲製作


















程式碼:
import ddf.minim.*;
Minim minim;
AudioPlayer song;
AudioPlayer songB;//Baclground Music
import de.voidplus.leapmotion.*;
PImage img2, img0, img5;
LeapMotion leap;
PImage imgBG;
PImage imgM, imgM1, imgM2;
PImage imgPipe;
PImage imgGap1, imgGap2, imgGap3, imgGap4, imgGap5, imgGap6;
PImage imgGhost, imgStar, imgGhost2;
PImage imgWin, imgLose;
PImage i;
int lr, up;
int a=0;
boolean point=false;
boolean c=true;
boolean d;
int ghosty, starx, stary, ghost2y ;
int ghost2x=200;
int ghostx=400;

void setup() {
  size(600, 819);
  imgM = loadImage("mario.png"); //UP
  imgM1 = loadImage("mario1.png"); //RIGHT
  imgM2 = loadImage("mario2.png"); //LEFT
  imgPipe = loadImage("Mario Pipes.png");
  imgGap1 = loadImage("gap1.jpg");
  imgGap2 = loadImage("gap2.jpg");
  imgGap3 = loadImage("gap3.jpg");
  imgGap4 = loadImage("gap4.jpg");
  imgGap5 = loadImage("gap5.jpg");
  imgGap6 = loadImage("gap6.jpg");
  imgGhost = loadImage("ghost.png");
  imgGhost2 = loadImage("ghost.png");
  imgStar = loadImage("star.png");
  imgWin = loadImage("win.png");
  imgLose = loadImage("end.png");
  i=imgM1;

  minim = new Minim(this);
  leap = new LeapMotion(this);
  songB = minim.loadFile("background.mp3");
  songB.play();
}

void draw() {
  a++;
  imgBG = loadImage("H.jpg");
  background(imgBG);

  //Leap motion
  for (Hand hand : leap.getHands()) {
    int f=hand.countFingers();
    if (f==0||f==1) {//UP
      d=true;
      up-=126;
      i=imgM;
      song = minim.loadFile("jump.wav");
      song.play();
    }
    if (f==2||f==3) { //LEFT
      lr-=10;
      i=imgM2;
    }
    if (f==5||f==4) { //RIGHT
      lr+=10; 
      i=imgM1;
    }
    if (lr<=-100)lr=-100;
    if (lr>=460)lr=460;
    if (up<=-625)up=-625;

    if (100+lr>=528 && 652+up<=92)
    {
      song = minim.loadFile("win.mp3");
      songB.close();
      song.play();
      noLoop();
    }
  }

  strokeWeight(7);
  stroke(255, 21, 28);
  line(0, 100, 600, 100);
  stroke(234, 131, 38);
  line(0, 225, 600, 225);
  stroke(235, 225, 37);
  line(0, 350, 600, 350);
  stroke(72, 203, 69);
  line(0, 475, 600, 475);
  stroke(41, 150, 231);
  line(0, 600, 600, 600);
  stroke(189, 130, 242);
  line(0, 725, 600, 725);

  image(i, 100+lr, 652+up);
  image(imgPipe, 525, 10);
  image(imgGap1, -50, 95);
  image(imgGap2, 150, 220);
  image(imgGap3, 300, 345);
  image(imgGap4, 50, 470);
  image(imgGap5, 485, 595);
  image(imgGap6, 100, 720);
  image(imgGhost, ghostx, ghosty, 80, 80);
  image(imgGhost2, ghost2x, ghost2y, 80, 80);
  image(imgStar, starx, stary, 80, 80);
  //  image(imgstar, ghostx, ghosty, 80, 80);
  if (ghosty>=900)
  {
    float r= random(0, 5);
    int s=(int)r;
    switch(s) {
    case 0 :
      ghostx= 50;
      ghosty= 0;
      break; 
    case 1 :
      ghostx= 150;
      ghosty= 0;
      break;
    case 2 :
      ghostx= 300;
      ghosty= 0;
      break;
    case 3 :
      ghostx= 400;
      ghosty= 0;
      break;
    case 4 :
      ghostx= 500;
      ghosty= 0;
      break;
    }
  }
  ghosty+=15;
  if (ghosty >= 652+up && ghosty<= 652+up+100 && ghostx+40>=100+lr && ghostx+40 <= 100+lr+85)
  {
    image(imgLose, 0, 0);
    song = minim.loadFile("loser.mp3");
    songB.close();
    song.play();
    noLoop();
  }

  if (stary>=700)
  {
    image(imgLose, 0, 0);
    song = minim.loadFile("loser.mp3");
    songB.close();
    song.play();
    noLoop();
  }

  if (stary>=900)
  {
    float q= random(0, 3);
    int w=(int)q;
    switch(w) {
    case 0 :
      starx= 70;
      stary= 0;
      break; 
    case 1 :
      starx= 150;
      stary= 0;
      break;
    case 2 :
      starx= 300;
      stary= 0;
      break;
    }
  }
  stary+=3;
  if (stary >= 652+up && stary<= 652+up+100 && starx+40>=100+lr && starx+40 <= 100+lr+60)
  {   
    starx=10;
    stary=10;
    //song = minim.loadFile("loser.mp3");
    //song.play();
  }
  if (ghost2y>=900)
  {
    float rr= random(0, 5);
    int ss=(int)rr;
    switch(ss) {
    case 0 :
      ghost2x= 460;
      ghost2y= 0;
      break; 
    case 1 :
      ghost2x= 220;
      ghost2y= 0;
      break;
    case 2 :
      ghost2x= 550;
      ghost2y= 0;
      break;
    case 3 :
      ghost2x= 100;
      ghost2y= 0;
      break;
    case 4 :
      ghost2x= 340;
      ghost2y= 0;
      break;
    }
  }
  ghost2y+=10;
  if (ghost2y >= 652+up && ghost2y<= 652+up+100 && ghost2x+40>=100+lr && ghost2x+40 <= 100+lr+60)
  {
    image(imgLose, 0, 0);
    song = minim.loadFile("loser.mp3");
    songB.close();
    song.play();
    noLoop();
  }

  if (100+lr>=528 && 652+up<=92 )
  {
    c=false;
    image(imgWin, 0, 0);
    background(imgWin);
  }

  if (d) {
    if (100+lr>=485 && 100+lr<=596 && 652+up<=590 &&  652+up>=470) up=-126;
    else if (100+lr>=30 && 100+lr<=130 && 652+up<=465 &&  652+up>=350) up=-252;
    else if (100+lr >=300 && 100+lr<=390 && 652+up<=345 &&  652+up>=220) up=-378;
    //else if (100+lr>=500 && 100+lr<=636 && 336+up<=215 &&  652+up>=95) up=-504;
    else if (100+lr>=150 && 100+lr<=200 && 652+up<=150 && 652+up>=95) up=-504;
    else if (100+lr>=0 && 100+lr<=40 && 652+up<=90 ) up=-630;
    else up+=126;
    d=false;
  }
  //print(a+"\n");
}

沒有留言:

張貼留言