顯示具有 Midterm 標籤的文章。 顯示所有文章
顯示具有 Midterm 標籤的文章。 顯示所有文章

2013年11月18日 星期一

week10

期中作品
PImage map,map1,map2,gg,win;
int page=1;
int stage;

void setup(){

  size(600,500);
 map = loadImage("ggbun.png");
 map1 = loadImage("ggbun1.png");
 map2 = loadImage("ggbun2.png");
 gg = loadImage("gg.jpg");
 win = loadImage("win.png");
loadPixels();
}

void draw(){
  println(""+pixels[mouseX+mouseY*600]);
fill(pixels[mouseX+mouseY*600]);
if(pixels[mouseX+mouseY*600]==-16777216)
page=0; 
if(pixels[mouseX+mouseY*600]==-14503604)
page=2;

if(pixels[mouseX+mouseY*600]==-16735512)
page=3;

if(pixels[mouseX+mouseY*600]==-1237980)
page=4;
if (page==0)
image(gg,0,0);
if (page==1)
image(map,0,0);
if (page==2)
image(map1,0,0);
if (page==3)
image(map2,0,0);
if (page==4)
image(win,0,0);
loadPixels();

}

2013年11月11日 星期一

crazy zombie shoot 其中作品展示!!!!


我們是製作手機小遊戲的zombie shoot改制做成電腦版並且延伸
遊戲規則
利用1-8鍵盤,按下最下排的zombie位置即可得1分,以此類推
如果你射殺的zombie超過50隻,就會變成紅色的zombie並且殺一隻提高為得2分
計時30秒,累計你射殺的zombie數,最後會統計得分於畫面
配合背景音樂,讓你隨著律動玩遊戲ㄏㄏ

因為此processing為太新版
所以顯示不出國字
舊版即可

程式碼:
import ddf.minim.*;
Minim m;
AudioPlayer player;
int []bz=new int[1000];
PImage imgZombie;
PImage imgRZombie;
PImage imgShoot;

void setup() {

  size(800, 600);
  imgZombie=loadImage("zombie.jpg");
  imgRZombie=loadImage("Rzombie.jpg");
  imgShoot=loadImage("shoot.jpg");
  for (int i=0;i<1000;i++) {
    bz[i]=int(random(8));
  }


  m = new Minim(this);  //
  player = m.loadFile("hww.mp3");
  player.play();  //播放背景音樂
}

int now=0;
int a;
int total=0;
int countDown=90;
int countDown2=1860;

void draw() {
  int a=0;
  if (a==0) {
    if (countDown>0) {     //倒數三秒準備開始遊戲
      background(70, 53, 1);
      countDown--;
      textSize(100);
      text(countDown/30+"秒", 350, 300);
      return;
    }
    a++;
  }
  background(70, 53, 1);
  if (a==1) {

    if (countDown2>0) {  //倒數30秒遊戲中
      countDown2--;
      textSize(50);
      text(countDown2/60+"秒", 20, 40);
      for (int i=now;i<now+5;i++) {
        if (now<=50)image(imgZombie, bz[i]*100, 400-(i-now)*100);
        if (now>50)image(imgRZombie, bz[i]*100, 400-(i-now)*100);
      }
      image(imgShoot, 0, 500);
      image(imgShoot, 100, 500);
      image(imgShoot, 200, 500);
      image(imgShoot, 300, 500);
      image(imgShoot, 400, 500);
      image(imgShoot, 500, 500);
      image(imgShoot, 600, 500);
      image(imgShoot, 700, 500);
    }
    a++;
  }
 
  if (a==2) {
    if (countDown2/60==0)text("哇!好棒"+total+"分", 300, 350);//結尾計分
  }
}

void keyPressed() {

  if (key==bz[now]+'1')
  {
    if (total<50)a=1;
    if (total==50)a=2;
    if (countDown2/60==0)a=0;
    now++;
    total=total+a;
  }
}

Week10_期中DEMO

##DEMO影片



##程式碼
PImage starS, winP, loseP, starT, ansOne, falloW, nexT, agaiN, ansTwo;

int Z,zZ;
int D1=0, D2=6;
int j=0, W;
int clickCount = 0;

int []Ponx= { 100, 400, 250, 100, 400}; 
int []Ponx2= { 125, 375, 75, 425, 250};
int []Pony= { 400, 400, 275, 150, 150}; 
int []Pony2= { 425, 425, 175, 175, 75};

int []PPx= { 125, 425, 275, 125, 425}; 
int []PPx2= { 250, 500, 200, 550, 375};
int []PPy= { 425, 425, 300, 175, 175}; 
int []PPy2= { 550, 550, 300, 300, 350};

int []x= { 6, 6, 6, 6, 6, 6, 6}; 
int []x2= { 6, 6, 6, 6, 6, 6};

int []ans1= { 0, 2, 4, 1, 2, 3, 0}; 
int []ans5= { 0, 4, 1, 2, 3, 0};
int []ans2= { 0, 2, 1, 4, 2, 3, 0}; 
int []ans6= { 0, 3, 2, 1, 4, 0};
int []ans3= { 0, 3, 2, 4, 1, 2, 0};
int []ans4= { 0, 3, 2, 1, 4, 2, 0};

void setup()

   size(900, 600);
   background(24, 20, 90);
   starS=loadImage("http://i.imgur.com/Oxs9TWM.png?1");
   winP=loadImage("http://i.imgur.com/Sx6NCzf.jpg");
   loseP=loadImage("http://i.imgur.com/0tJ86T7.jpg?1");
   ansOne=loadImage("http://i.imgur.com/HRVkRHp.png");
   starT=loadImage("http://i.imgur.com/NoZ4MqU.png?1");
   falloW=loadImage("http://i.imgur.com/oxcZTaE.png");
   nexT=loadImage("http://i.imgur.com/4hb4Cln.png");
   agaiN=loadImage("http://i.imgur.com/BdxdTvl.png");
   ansTwo=loadImage("http://i.imgur.com/tFNyu4o.png");
  sett1();
}

void sett1()
{
   image(starS, Ponx[0], Pony[0], 50, 50);
   image(starS, Ponx[1], Pony[1], 50, 50);
   image(starS, Ponx[2], Pony[2], 50, 50);
   image(starS, Ponx[3], Pony[3], 50, 50);
   image(starS, Ponx[4], Pony[4], 50, 50);
   image(starT, 55, 455, 150, 80);
   image(falloW, 600, 190, 200, 40);
   image(ansOne, 600, 250, 200, 200);
}

void sett2()
{
   image(starS, Ponx2[0], Pony2[0], 50, 50);
   image(starS, Ponx2[1], Pony2[1], 50, 50);
   image(starS, Ponx2[2], Pony2[2], 50, 50);
   image(starS, Ponx2[3], Pony2[3], 50, 50);
   image(starS, Ponx2[4], Pony2[4], 50, 50);
   image(starT, 55, 500, 150, 80);
   image(falloW, 600, 190, 200, 40);
   image(ansTwo, 600, 250, 200, 200);
}

void mouseClicked()
{
   if(mouseButton==LEFT)
   {
      if (Ponx[0]<=mouseX&&mouseX<=Ponx[0]+50&&Pony[0]<=mouseY&&mouseY<=Pony[0]+50) 
      {
          Z=0; 
      }
      else if (Ponx[1]<=mouseX&&mouseX<=Ponx[1]+50&&Pony[1]<=mouseY&&mouseY<=Pony[1]+50)
      { 
         Z=1; 
      }
      else if (Ponx[2]<=mouseX&&mouseX<=Ponx[2]+50&&Pony[2]<=mouseY&&mouseY<=Pony[2]+50)
      {
         Z=2; 
      }
     else if (Ponx[3]<=mouseX&&mouseX<=Ponx[3]+50&&Pony[3]<=mouseY&&mouseY<=Pony[3]+50)
      {
         Z=3;
      }
      else if (Ponx[4]<=mouseX&&mouseX<=Ponx[4]+50&&Pony[4]<=mouseY&&mouseY<=Pony[4]+50)
      {
         Z=4; 
      }

      x[clickCount]=Z;
      clickCount++;
      println("====");
      for (j=0;j < x.length; j++)
      { 
         println(x[j]);
      }

      if (clickCount > 6)
      { 
         check();
      }
   }

   else if(mouseButton==RIGHT)
   {
      if (450<=mouseX&&mouseX<=600&&150<=mouseY&&mouseY<=200) 
      { 
         background(24, 20, 90);
         sett2();
      }
      else if (450<=mouseX&&mouseX<=600&&450<=mouseY&&mouseY<=500)
      {
         background(24, 20, 90);
         sett1();
      }
   }

   if (D1!=6)
   {
      D2=Z; 
      draw();
      D1=D2; 
      D2=6;
   }
}

void draw()
{
   if (D1==0 && D2==1 || D1==1 && D2==0)
   line(PPx[0], PPy[0], PPx[1], PPy[1]);

   else if (D1==0 && D2==3 ||D1==3 && D2==0 ) 
   line(PPx[0], PPy[0], PPx[3], PPy[3]);

   else if (D1==2 && D2==0 ||D1==0 && D2==2 )
   line(PPx[0], PPy[0], PPx[2], PPy[2]);

   else if (D1==1 && D2==2 ||D1==2 && D2==1 )
   line(PPx[1], PPy[1], PPx[2], PPy[2]);

   else if (D1==1 && D2==4 ||D1==4 && D2==1 ) 
   line(PPx[1], PPy[1], PPx[4], PPy[4]);

   else if (D1==2 && D2==3 ||D1==3 && D2==2 ) 
   line(PPx[2], PPy[2], PPx[3], PPy[3]);

   else if (D1==2 && D2==4 ||D1==4 && D2==2 ) 
   line(PPx[2], PPy[2], PPx[4], PPy[4]);

   else if (D1==3 && D2==4 ||D1==4 && D2==3 ) 
   line(PPx[3], PPy[3], PPx[4], PPy[4]);
}

void check()
{
   for (int i=0;i<7;i++)//check ans1
   {
      if (x[i]==ans1[i])
      W=1;
      else 
      { 
         W=0; 
         i=7;
      }
   }
   if (W==0) //not ans1,check ans2
   { 
      for (int i=0;i<7;i++)//check ans2
      {
         if (x[i]==ans2[i])
         W=1;
         else
         { 
            W=0; 
            i=7;
         }
      }
      if (W==0) //not ans2,check ans3
      { 
         for (int i=0;i<7;i++)//check ans3
         {
            if (x[i]==ans3[i])
            W=1;
            else
            { 
               W=0; 
               i=7;
            }
         }
         if (W==0) //not ans3,check ans4
         { 
            for (int i=0;i<7;i++)//check ans4
            {
               if (x[i]==ans4[i])
               W=1;
               else 
               { 
                  W=0; 
                  i=7;
               }
            }
            if (W==0) //not ans4,All not end
            {
               lose();
            }
               else if (W==1) //ans4 OK
               {
                  win();
               }
            }
            else if (W==1) //ans3 OK
            {
               win();
            }
         }
         else if (W==1) //ans2 OK
         {
            win();
         }
      }
   else if (W==1) //ans1 OK
   {
      win();
   }
}

void win()
{
   image(winP, 100, 150, 350, 350);
   image(nexT, 450, 150, 150, 80);
}

void lose()
{
   image(loseP, 100, 150, 350, 350);
   image(agaiN, 450, 450, 150, 80);
}

2013年11月10日 星期日

第十週期中作品展示

黃敦群與陳建勳的作品
我們是要照順序接漢堡素材,若接錯順序或是時間內沒有接完就會GameOver!!

PImage img;
PImage img2;
PImage img3;
int N=20;
PImage img4;
PImage img5;
PImage img6;
PImage img7;
PImage img8;
PImage img9;
PImage img10;
float a, b, c, d, e;
int A1=0;
int A2=0;
int A3=0;
int A4=0;
int A5=0;
int G1=0;
int G2=0;
int G3=0;
int G4=0;
int G5=0;
float B1=0;
float B2=0;
float B3=0;
float B4=0;
float B5=0;
int C1, C2, C3, C4, C5;
int L=330;
int I1, I2, I3, I4, I5;
float []thingAA = new float[N];
float []thingBB = new float[N];
float []thingCC = new float[N];
float []thingDD = new float[N];
float []thingEE = new float[N];

float x=random(0, 600);
float y=random(0, 600);
float z=random(0, 600);
float w=random(0, 600);
float v=random(0, 600);

int R=0;
import ddf.minim.*;

AudioPlayer player;
AudioPlayer player1;
AudioPlayer player2;

Minim minim;//audio context

void setup() {
  size(600, 400);
  I1=0;
  I2=0;
  I3=0;
  I4=0;
  I5=0;
  thingAA[0]=int(random(5, 7));
  thingBB[0]=int(random(5, 7));
  thingCC[0]=int(random(5, 7));
  thingEE[0]=int(random(5, 7));
  thingDD[0]=int(random(5, 7));
  img = loadImage("01.jpg");
  img2 = loadImage("down.jpg");
  img3 = loadImage("meet.jpg");
  img4 = loadImage("cheese.jpg");
  img5 = loadImage("vegetable.jpg");
  img6 = loadImage("top.jpg");
  img7 = loadImage("dish.jpg");
  img8 = loadImage("win.jpg");
  img9 = loadImage("lose.jpg");
  img10= loadImage("start.jpg");
  minim = new Minim(this);
  player = minim.loadFile("file.mp3", 2048);
  player1 = minim.loadFile("winner.wav", 2048);
  player2 = minim.loadFile("loser.WAV", 2048);
}
void draw() {

  if (R==0) {
    background(img10);
    A1=0;
    A2=0;
    A3=0;
    A4=0;
    A5=0;
    G1=0;
    G2=0;
    G3=0;
    G4=0;
    G5=0;
    B1=0;
    B2=0;
    B3=0;
    B4=0;
    B5=0;

    L=330;

    x=random(0, 600);
    y=random(0, 600);
    float z=random(0, 600);
    float w=random(0, 600);
    float v=random(0, 600);

    I1=0;
    I2=0;
    I3=0;
    I4=0;
    I5=0;
    thingAA[0]=int(random(5, 7));
    thingBB[0]=int(random(5, 7));
    thingCC[0]=int(random(5, 7));
    thingEE[0]=int(random(5, 7));
    thingDD[0]=int(random(5, 7));
  }
  if (I1<=10 && I2<=10 && I3<=10 && I4<=10. && I5<=10 && L!=230 && R==1) {
    background(img);
    image(img7, mouseX, 350, 80, 60);

    if (thingAA[I1]==5) {
      a=a+5;
      image(img2, x, a, 60, 40);
    }
    if (thingAA[I1]!=5)
    {
      thingAA[I1]=int(random(5, 25));
    }

    if (thingBB[I2]==5) {
      b=b+5;
      image(img3, y, b, 60, 40);
    }
    if (thingBB[I2]!=5)
    {
      thingBB[I2]=int(random(5, 25));
    }

    if (thingCC[I3]==5) {
      c=c+5;
      image(img4, z, c, 60, 40);
    }
    if (thingCC[I3]!=5)
    {
      thingCC[I3]=int(random(5, 25));
    }

    if (thingDD[I4]==5) {
      d=d+5;
      image(img5, w, d, 60, 40);
    }
    if (thingDD[I4]!=5)
    {
      thingDD[I4]=int(random(5, 25));
    }

    if (thingEE[I5]==5) {
      e=e+5;
      image(img6, v, e, 60, 40);
    }
    if (thingEE[I5]!=5)
    {
      thingEE[I5]=int(random(5, 25));
    }

    if (a==400) {
      I1=I1+1;
      thingAA[I1]=int(random(5, 8));
    }
    if (b==400) {
      I2=I2+1;
      thingBB[I2]=int(random(5, 8));
    }
    if (c==400) {
      I3=I3+1;
      thingCC[I3]=int(random(5, 8));
    }
    if (d==400) {  
      I4=I4+1;
      thingDD[I4]=int(random(5, 8));
    }
    if (e==400) {
      I5=I5+1;
      thingEE[I5]=int(random(5, 8));
    }


    if (a==400) {
      a=0;
      x = random(0, 600);
    }

    if (b==400) {
      b=0;
      y = random(0, 600);
    }

    if (c==400) {
      c=0;
      z = random(0, 600);
    }

    if (d==400) {
      d=0;
      w = random(0, 600);
    }

    if (e==400) {
      e=0;
      v = random(0, 600);
    }

    if (a==L && x <= mouseX+20 && x>= mouseX-20 && G1==0)
    {
      A1=1;
      B1=mouseX-x;
      C1=L;
      L=L-20;
      G1=1;
    }
    if (A1==1&&G1==1) {
      image(img2, mouseX+B1, C1, 60, 40);
    }

    if (b==L && y <= mouseX+20 && y>= mouseX-20 && G2==0)
    {
      A2=1;
      B2=mouseX-y;
      C2=L;
      L=L-20;
      G2=1;
    }
    if (A2==1&&G2==1) {
      image(img3, mouseX+B2, C2, 60, 40);
    }

    if (c==L && z <= mouseX+20 && z>= mouseX-20 && G3==0)
    {
      A3=1;
      B3=mouseX-z;
      C3=L;
      L=L-20;
      G3=1;
    }
    if (A3==1&&G3==1) {
      image(img4, mouseX+B3, C3, 60, 40);
    }


    if (d==L && w <= mouseX+20 && w>= mouseX-20 && G4==0)
    {
      A4=1;
      B4=mouseX-w;
      C4=L;
      L=L-20;
      G4=1;
    }
    if (A4==1&&G4==1) {
      image(img5, mouseX+B4, C4, 60, 40);
    }

    if (e==L && v <= mouseX+20 && v>= mouseX-20 && G5==0)
    {
      A5=1;
      B5=mouseX-v;
      C5=L;
      L=L-20;
      G5=1;
    }
    if (A5==1&&G5==1) {
      image(img6, mouseX+B5, C5, 60, 40);
    }
  }
  else {
    if (R!=0) {
      if (C1==330&&C2==310&&C3==290&&C4==270&&C5==250) {
        background(img8);
        R=2;
     
        player1.play();
      }
      else
      {
        background(img9);
        R=3;
        player2.play();
      }
    }
  }
 }

void mouseClicked()
{
  if (R==0) {
    player.play();
    R=1;
  }
  if (I1==10 || I2==10 || I3==10 || I4==10 || I5==10 || L==230 )
    R=0;
}

void stop()
{
 player.close();
 minim.stop();
 super.stop();
}


week10 黃柏勳 林俊廷 期中作品

https://www.facebook.com/l.php?u=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXl7Y2vYZj9g%26feature%3Dyoutu.behttps%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXl7Y2vYZj9g%26feature%3Dyoutu.be&h=rAQGgL5za
這是我們的期中作品 : 今天拆大埔 明天拆政府之b羅的逆襲
用asop四個鍵來控制 as往左 op往右
先把b羅送到對方的陣營就獲勝!

week10 期中作品展示


Week10 葉玉婷 期中作品

遊戲影片

第一次為失血而Game over
第二次為沒準時回家而Game over
第三次為拿到鑰匙並準時回家而Win



遊戲畫面
開始畫面(遊戲解說及倒數)

小蝸回不了家
必須先拿完鑰匙才可以回家
在時間內完成這件事
PS.碰到其他人會扣血、吃到棒棒糖會加分呦

遊戲中畫面(左上角血量,左下角房子,右上角鑰匙,人物隨機由上往下,糖果隨機跑)

血量沒有時死掉的畫面

沒有在時間內拿鑰匙並回家

有在時間內拿鑰匙並回家(評價依吃到的棒棒糖數量評)




程式碼
int []sea=new int[1000];
int []seaNo=new int[1000];
int blood=30;  //血量
float ManX=25, ManY=480; //小蝸的位置
PImage []img = new PImage[4];
PImage bg; //背景圖
PImage bg0; //鳳梨屋
PImage key1; //鑰匙
PImage Man; //小蝸
int a=1; //判斷是否拿到鑰匙
int S=20; //判斷是否被人碰到或是吃到糖果
float [] ballX=new float [50],ballY=new float[50]; //隨機亂跑的棒棒糖
float [] ballVX=new float [50],ballVY=new float[50]; //隨機亂跑的棒棒糖
PImage imgBall; //棒棒糖

//音樂
import ddf.minim.*;
Minim m;
AudioPlayer player;
AudioPlayer da;

void setup()
{
  m=new Minim(this);

  for(int i=0;i<50;i++) //棒棒糖
    {
      newBall(i);
    }
  player=m.loadFile("C://Users//S405-14//Desktop//processing//music.mp3");  //背景音樂
  da=m.loadFile("C://Users//S405-14//Desktop//processing//001.mp3"); //小蝸走動的聲音
  player.play();  //播放
  imgBall=loadImage("C://Users//S405-14//Desktop//processing//candy.png"); //糖果圖
  bg = loadImage("C://Users//S405-14//Desktop//processing//back.jpg");  //背景圖
  bg0=loadImage("C://Users//S405-14//Desktop//processing//home.png"); //鳳梨屋圖
  Man= loadImage("C://Users//S405-14//Desktop//processing//e.png"); //小蝸圖
  key1=loadImage("C://Users//S405-14//Desktop//processing//key.png"); //鑰匙圖
  size(500, 500);  //視窗尺寸

  img[0]=loadImage("C://Users//S405-14//Desktop//processing//a.png"); //人物一
  img[1]=loadImage("C://Users//S405-14//Desktop//processing//b.png"); //人物二
  img[2]=loadImage("C://Users//S405-14//Desktop//processing//c.png"); //人物三
  img[3]=loadImage("C://Users//S405-14//Desktop//processing//d.png"); //人物四


  for (int i=0;i<1000;i++) //用來隨機產生人
  {
    sea[i]=int(random(4));
    seaNo[i]=int(random(4));
  }
}

int tick=0;
int now=0;
int total=0; //總分
int countDown=4*30; //開始前的倒數
int countDown2=60*30; //遊戲中的倒數

void draw()
{
  if (countDown>0) //遊戲開始前
  {
    background(0, 0, 0);
    countDown--; //倒數
    //遊戲解說
    text("小蝸被鎖在門外了!!  請幫助小蝸拿到鑰匙(右上角)", 150, 100);
    text("請注意別被其他人撞到囉!! (會扣血)", 150, 150);
    text("吃到棒棒糖可以加分喲!", 150, 200);
    text("倒數"+countDown/30+"秒", 150, 250);
    return;
  }

  if (countDown2>0) //遊戲開始
  {

    background(bg); //背景
    image(key1, 490, 20); //鑰匙位置
    if(a==0)//如果吃到鑰匙則消失
    {
      image(bg,250,250);
    }
 
    countDown2--; //倒數
    text("剩下"+countDown2/30+"秒", 250, 250); //顯示倒數時間

    for (int i=now;i<now+5;i++) //人物跑動的位置
    {
      image(img[seaNo[i]], sea[i]*100+100, tick+400-(i-now)*100); //人物在跑

      if(dist(sea[i]*100+100,tick+400-(i-now)*100,ManX,ManY)<S) //判斷有沒有接觸到人
      {
          /*sea[i]=500;*/
          blood-=1; //碰到血會變少

      }
    }
    tick+=2;
    if (tick>100)
    {
      tick=0;
      now++;
    }
 
    for(int i=0;i<50;i++) //棒棒糖隨機跑
    {
     image(imgBall,ballX[i],ballY[i],20,20);
     ballX[i]+=ballVX[i];
     ballY[i]+=ballVY[i];
     if(ballX[i]<0 || ballX[i]>500 || ballY[i]<0 || ballY[i]>500) //判斷有沒有超出視窗
     {
       newBall(i);
     }
     if(dist(ballX[i],ballY[i],ManX,ManY)<S) //判斷有沒有吃到棒棒糖
     {
       ballX[i]=0;
       total++;
     }
    }
    if (blood<=0) //血沒了
    {
      m.stop(); //音樂暫停
      background(0, 0, 0); //背景為黑
      text("Game over",250,150);
      text("死掉惹",250,200);
      text("You lose!", 250,250);
    }
  }
  else //血還有但是沒有成功達到任務
  {
    m.stop();
    background(0, 0, 0);
    fill(255,255,255);
    text("Game over",250,150);
    text("要趕快拿鑰匙回家啊!!!",250,200);
    text("You lose!", 250,250);
 
  }

  if(a==0 && ManX<=50 && ManY>=480) //有吃到鑰匙且成功回到屋子
  {
    m.stop(); //音樂暫停
    background(0, 0, 0); //背景為黑
    fill(255,255,255);
    text("You win!",250,150); //贏了
    text("恭喜小蝸賀喜小蝸",250,200);
    //評語
    if(total<=20)
      text("評價:蛤太弱了喔", 250,250);
    if(total<=40 && total>20)
      text("評價:普普通通啦", 250,250);
    if(total<=55 && total>40)
      text("評價:還不賴嘛!", 250,250);
    if(total>55)
      text("評價:厲害!", 250,250);
  }

  imageMode(CENTER);
  fill(255, 0, 0);
  rect(0, 0, blood*3, 50); //血量

  text("得"+total+"分", 250, 300); //倒數時間

  if(mouseX<100 && mouseY<50) //解說
    text("血量", 180, 30);
  if(mouseX>450 && mouseY<50) //解說
    text("鑰匙", 400, 30);
  if(mouseX<100 && mouseY>400) //解說
    text("鳳梨屋", 150, 450);

     
  if(ManX>=470 && ManY<=20) //如果拿到鑰匙
  {
     fill(0,0,0);
     text("得到鑰匙", 400, 20);
     text("快回家吧", 400, 50);
     a=0;
  }

    image(bg0, 40, 430,100,150); //鳳梨屋圖
    image(Man, ManX, ManY); //小蝸圖
}

void keyPressed()
{
  if (key=='8') //上
  {
    da.rewind();
    da.play();
    ManY-=20;
  }
  if (key=='2') //下
  {
    da.rewind();
    da.play();
    ManY+=20;
  }
  if (key=='6') //左
  {
    da.rewind();
    da.play();
    ManX+=20;
  }
  if (key=='4') //右
  {
    da.rewind();
    da.play();
    ManX-=20;
  }
}

void newBall(int i) //隨機棒棒糖
{
  float angle=random(2*PI);
  ballVX[i]=cos(angle);
  ballVY[i]=sin(angle);
  int dir=int(random(4));

  if(dir==0)
  {
     ballX[i]=random(600); ballY[i]=0;
  }
  else if(dir==1)
  {
     ballX[i]=random(600); ballY[i]=0;
  }
  else if(dir==2)
  {
     ballX[i]=0; ballY[i]=random(600);
  }
  else if(dir==3)
  {
     ballX[i]=600; ballY[i]=random(600);
  }

}

Week10 張智棠,期中作品展示

期中作品展示


程式碼 :

import ddf.minim.*;
AudioPlayer playerDead,playerST1,playerending,playerST2;
Minim minim;
float loc = 0 ;
int  N = 10 ,score = 0,blood=100;
int PX=100,PY=701;
PImage coin , cone , fire,stageBG2,stageBG4,stageBG5,people,copyright,copyright2;
int []thingType = new int [10] ;
float []thingY = new float [10];
float []thingX = new float [10];
float HeadX=200,HeadY=600;
int stage = 1;
int shoes = 0,jumper=0;

void setup ()
{
  size (600, 800) ;
  coin = loadImage("coin.jpg") ;
  cone = loadImage("cone.jpg") ;
  fire = loadImage("image.jpg");
  stageBG4 = loadImage("gameover.jpg");
  stageBG2 = loadImage("stageBG2.bmp");
  people = loadImage("people.jpg");
  copyright = loadImage("copyright.bmp");
  copyright2 = loadImage("copyright2.bmp");
  for ( int i = 0 ; i < N ; i++)
  {
     newThing(i);
  }
  minim = new Minim(this);
  playerDead = minim.loadFile("warawa.mp3");
  playerST1 = minim.loadFile("ST1.mp3");
  playerST2 = minim.loadFile("ST2.mp3");
  playerending = minim.loadFile("ending.mp3");
 
}
int now = 0 ;
void draw ()
{
 
 if (stage==1)
 {
   playerST1.pause();
   playerDead.pause();
   background(255,255,255);
   image(people,150,450,30,58);
   fill(#1A1717);
   textSize(12);
   text("Matchstick Men are suffering from the strange thing!",100,100);
   text("He want to find he's friend to help him",100,200);
   textSize(25);
   text("Rule :",100,250);
   textSize(12);
   text("Catch TEN COIN can stop the strange thing for a while",100,300);
   text("Catech the other thing may cause a damage from himself",100,400);
   textSize(32);
   text("Press S or s to Play ", 150, 700);
 }
  if (stage==2)
  {
    background(255);
    playerST1.pause();
    playerST2.setGain(-20);
    playerST2.play();
   
    score = 0;
    blood = 100;

    image(stageBG2,0,0,600,800);
    image(people,PX,PY,30,58);
   
    if (150<PX&&PX<250&&550<PY&&PY<650)
    {
      shoes=1;
      textSize(25);
      text("You Get a shoes!",200,500);
      text("Triple MoveSpeed!",200,600);
    }
    if (300<PX&&PX<450&&400<PY&&PY<500) PY-=200;
    if (500<PX&&PX<600&&0<PY&&PY<100) stage=5;
   
   
    if (PY%80==0) stage=3;

  }
  if (stage==5)
  {
    playerST2.pause();
    background(0,0,0);
    playerending.setGain(-20);
    playerending.play();
    textSize(35);
    text("Matchstick Men Finally ",100,100);
    text("arrival His Friends Side!",100,150);
    text("You Made It!",100,200);
    text("Thanks For Your Playing!",100,400);
    text("   This Game Done by↓",100,500);
    text("&",310,580);
    image(copyright,250,550,39,33);
    image(copyright2,350,550,39,33);
  }
  if (stage == 4)
  {
    playerST1.pause();
    playerST2.pause();
    image(stageBG4,0,0,600,800);
    fill(0,255,0);
    textSize(32);
    text("Game Over", 200, 350);
    playerDead.play();

  }
  if (stage ==3)
  {
    background(255);
    fill(0,0,255);
    textSize(32);
    text("Life",100,800);
    fill(255,0,0);
    rect(100,700,blood,50);
    playerST2.pause();
   
    playerST1.setGain(-20);
    playerST1.play();
    textSize(12);
    text("Use",545,760);
    text("← → ",545,780);
    text("to Move",545,800);
    textSize(25);
    text("coin : "+score,400,760);
   
   
    for ( int i = 0 ; i < N ; i++)
    {
      if (thingType[i] == 1 )
      {
         drawcoin(i) ;
         if ( dist(thingX[i],thingY[i],HeadX,HeadY)<50)
        {
          score++;
          if (blood<100) blood+=5;
          thingY[i] =620;
        }
      }
      else if (thingType[i] == 2 )
     {
       drawcone(i) ;
        if ( dist(thingX[i],thingY[i],HeadX,HeadY)<50)
        {
          blood-=10;
          thingY[i] =620;
        }
     }
      else if (thingType[i] == 3 )
      {
        drawfire(i) ;
         if ( dist(thingX[i],thingY[i],HeadX,HeadY)<50)
         {
          blood-=20;
          thingY[i] =620;
         }
      }
      thingY[i] += 4 ;
      if (score>2) thingY[i] += 5 ;
      if (score>6) thingY[i] += 7 ;
      if (thingY[i] > 600 ) newThing(i) ;  
     
    }
    people(loc) ;
    if (blood <1) stage = 4;
    if (score ==10) 
    {
      PY-=1;
      stage = 2;
    }
  }
}

void people (float x) {
    noFill();
    ellipse (225+x, 600, 30, 30) ;
    line ( 225+x, 615, 225+x, 660 );
    line ( 225+x, 625, 205+x, 640) ;
    line ( 225+x, 625, 245+x, 640) ;
    line ( 225+x, 660, 205+x, 680) ;
    line ( 225+x, 660, 245+x, 680) ;
}
void keyPressed()
{
  if (stage==1)
  {
    if (key=='s' || key =='S') stage=2;
  }
  else if (stage==2)
  {
    if(shoes==1)
    {
      if (keyCode==UP) PY-=3;
      if (keyCode==LEFT) PX-=3;
      if (keyCode==RIGHT)PX+=3;
      if (keyCode==DOWN) PY+=3;
    }
    else
    {
      if (keyCode==UP) PY-=1;
      if (keyCode==LEFT) PX-=1;
      if (keyCode==RIGHT)PX+=1;
      if (keyCode==DOWN) PY+=1;
    }
   
  }
  else if (stage==3)
  {
    if (key=='s' || key =='S') stage=2;
    if ( keyCode ==RIGHT)
    {
      loc += 200;
      if (loc >200) loc = 200;
      HeadX = loc+225;
    }
    if ( keyCode ==LEFT)
    {  
      loc -= 200;
      if (loc < -200 ) loc = -200;
      HeadX = loc+225;
    }
  }
}

void newThing(int i )

  thingY[i] = -random(300) ;
  thingX[i] = int(random(10)) * 200  ;
  thingType[i] = int (random(3)+1) ;
}

void drawcoin(int i)
{
  image(coin , thingX[i],thingY[i], 60,60) ;
}

void drawcone(int i)
{
  image(cone , thingX[i] , thingY[i] , 60 , 60) ;
}

void drawfire (int i )
{
  image(fire , thingX[i] , thingY[i] , 60 , 60) ;
}


void stop()
{
  playerDead.close();
  playerST1.close();
  playerending.close();
  minim.stop();
  super.stop();
}