2012年11月13日 星期二

Midterm

期中作品

影片



截圖


一開始的畫面
滑鼠點選"開始遊戲"後,切換到"鐵板"的畫面

滑鼠點選"遊戲說明"後,切換到"遊戲說明"的畫面
 
製作章魚燒的鐵板


Time's up  &  Game Over的畫面
(滑鼠點選"離開遊戲"後,切換到這個畫面) 




 程式碼

float r=0.01;
int savedTime; //計時器時間
int bg=1;
PImage bg1, vv, pp, over, e, fff, tako1, all;
int state=0;
int ellipse1 = 0;


void setup() {
  size(800, 600);
  savedTime = millis();  //儲存遊戲開始的時間(只執行一次)
  bg1 = loadImage("bg1.jpg");
  vv = loadImage("vv.jpg");
  pp = loadImage("pp1.jpg");
  over = loadImage("bg4.jpg");
  e = loadImage("turtle.jpg");
  fff = loadImage("fff.jpg");
  tako1 = loadImage("tako1.jpg");
  all = loadImage("06.jpg");
}

void draw() {
  println(mouseY);
  if (bg==1) {
    image(bg1, 0, 0, 800, 600);  //一開始執行的畫面
    if (mousePressed && mouseX>=555 && mouseX<=794 && mouseY>=261 && mouseY<=396) {
      image(pp, 0, 0);
      bg=2;  //滑鼠點選"開始遊戲"後,切換到"鐵板"的畫面
    }
    else if (mousePressed && mouseX>=550 && mouseX<=800 && mouseY>=420 && mouseY<=550) {
      bg=3;  /滑鼠/點選"遊戲說明"後,切換到"遊戲說明"的畫面
    }
  }
  if (bg==3) {
    image(vv, 0, 0, 800, 600);  //"遊戲說明"的畫面
    if (mousePressed && mouseX>=255 && mouseX<=465 && mouseY>=498 && mouseY<=594) {
      image(pp, 0, 0, 800, 600);
      bg=2;  //滑鼠點選"開始遊戲"後,切換到"鐵板"的畫面
    }
  }

  if (bg==2) {  //鐵板的畫面
    int passedTime = (millis() - savedTime)/100; //經過的秒數
    if (passedTime<600) {
      image(e, 683, passedTime, 120, 98);
    }
    else if (passedTime>=600) image(over, 0, 0, 800, 600);
    println(passedTime);
    if (mousePressed && mouseX>=485 && mouseX<=645 && mouseY>=542 && mouseY<=584) {
      image(over, 0, 0);
      bg=4;  //遊戲結束的畫面
    }
    if (mousePressed && mouseX>50 && mouseX<90 && mouseY>500 && mouseY<540) { 
      state = 1;
    }
    if (mousePressed && mouseX>150 && mouseX<190 && mouseY>500 && mouseY<540) {
      state = 2;
    }
    if (mousePressed && mouseX>250 && mouseX<290 && mouseY>500 && mouseY<540) {
      state = 3;
    }
    if (mousePressed && mouseX>350 && mouseX<390 && mouseY>500 && mouseY<540) {
      state = 4;
    }
    if (state == 1) {
      if (mousePressed && mouseX>40 && mouseX<160 && mouseY>40 && mouseY<160) {
        if (passedTime<100) {
          fill(239, 228, 176);  //白
          ellipse(100, 100, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(100, 100, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(100, 100, 120, 120);
        }
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>190 && mouseY<310) {
        if (passedTime<100) {
          fill(239, 228, 176);  //白
          ellipse(100, 250, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(100, 250, 120, 120);
        }
        else if (passedTime>=100) {
          fill(223, 147, 51);  //熟
          ellipse(100, 250, 120, 120);
        }
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>340 && mouseY<460) {
        if (passedTime<100) {       
          fill(239, 228, 176);  //白
          ellipse(100, 400, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(100, 400, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(100, 400, 120, 120);
        }
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>40 && mouseY<160) {
        if (passedTime<100) {
          fill(239, 228, 176);  //白
          ellipse(250, 100, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(250, 100, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(250, 100, 120, 120);
        }
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>190 && mouseY<310) {
        if (passedTime<100) {        
          fill(239, 228, 176);  //白
          ellipse(250, 250, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(250, 250, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(250, 250, 120, 120);
        }
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>340 && mouseY<460) {
        if (passedTime<100) {         
          fill(239, 228, 176);  //白
          ellipse(250, 400, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(250, 400, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(250, 400, 120, 120);
        }
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>40 && mouseY<160) {
        if (passedTime<100) { 
          fill(239, 228, 176);  //白
          ellipse(400, 100, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(400, 100, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(400, 100, 120, 120);
        }
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>190 && mouseY<310) {
        if (passedTime<100) { 
          fill(239, 228, 176);  //白
          ellipse(400, 250, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(400, 250, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(400, 250, 120, 120);
        }
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>340 && mouseY<460) {
        if (passedTime<100) { 
          fill(239, 228, 176);  //白
          ellipse(400, 400, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(400, 400, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(400, 400, 120, 120);
        }
      }//第三排
    }

    //手(加章魚至麵糊)
    if (state == 2) {
      if (mousePressed && mouseX>40 && mouseX<160 && mouseY>40 && mouseY<160) {
        image(tako1, 70, 70, 65, 65);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>190 && mouseY<310) {
        image(tako1, 70, 220, 65, 65);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>340 && mouseY<460) {
        image(tako1, 70, 370, 65, 65);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>40 && mouseY<160) {
        image(tako1, 220, 70, 65, 65);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>190 && mouseY<310) {
        image(tako1, 220, 220, 65, 65);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>340 && mouseY<460) {
        image(tako1, 220, 370, 65, 65);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>40 && mouseY<160) { 
        image(tako1, 370, 70, 65, 65);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>190 && mouseY<310) { 
        image(tako1, 370, 220, 65, 65);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>340 && mouseY<460) {
        image(tako1, 370, 370, 65, 65);
      }
    }
  
   //叉子   
    if (state == 3) {
      if (mousePressed && mouseX>40 && mouseX<160 && mouseY>40 && mouseY<160) {
        fill(43);
        ellipse(100, 100, 120, 120);
        image(fff, 510, 280, 50, 50);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>190 && mouseY<310) {
        fill(43);
        ellipse(100, 250, 120, 120);
        image(fff, 560, 280, 50, 50);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>340 && mouseY<460) {
        fill(43);
        ellipse(100, 400, 120, 120);
        image(fff, 560, 330, 50, 50);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>40 && mouseY<160) {
        fill(43);
        ellipse(250, 100, 120, 120);
        image(fff, 510, 330, 50, 50);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>190 && mouseY<310) {
        fill(43);
        ellipse(250, 250, 120, 120);
        image(fff, 510, 380, 50, 50);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>340 && mouseY<460) {
        fill(43);
        ellipse(250, 400, 120, 120);
        image(fff, 560, 380, 50, 50);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>40 && mouseY<160) { 
        fill(43);
        ellipse(400, 100, 120, 120);
        image(fff, 560, 430, 50, 50);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>190 && mouseY<310) { 
        fill(43);
        ellipse(400, 250, 120, 120);
        image(fff, 510, 430, 50, 50);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>340 && mouseY<460) {
        fill(43);
        ellipse(400, 400, 120, 120);
        image(fff, 535, 480, 50, 50);
      }
    }//state3
    if (state == 4) {
      //background(96,125,165);
      translate(400, 300);
      rotate(r);
      r+=0.01;
      image(all, 0, 0, 300, 383);
      //image(over, 0, 0, 800, 600);
    }
  }
}



心得及問題討論

  我們這次的期中作業遇到了麵糊變換顏色時間倒數的問題,後來請教老師跟助教,
有了一點方向,經過不斷的嘗試跟調整,我們終於完成了麵糊可以從白色→黃色→褐色(時間約經過15秒),但是我們原本的想法是希望麵糊每經過10秒後會自己變色
另外,我們了解到秒數的倒數計時程式不可以用second(),而是要用millis()千分之一秒。
  計時器部分,我們原本希望可以用兩個clock來紀錄不同的時間(烏龜的倒數計時,與麵糊改變顏色的計時),這是我們需要改進的地方。

  問題:我們目前只能完成一盒章魚燒,希望能繼續延伸製作第二盒甚至更多章魚燒。
物件及畫面可以再做調整,並需要加入更多限制使遊戲更完整、更有挑戰性。



沒有留言:

張貼留言