2012年11月13日 星期二

Midterm 期中作品


我們這組所做的期中作品為"阿寶上樓梯"
也就是所謂的小朋友上樓梯遊戲
這是遊戲剛開始的畫面 玩家要控制空白鍵 讓阿寶能夠跳躍

這是跳躍起來的樣子

  之後越跳越高,一階一階往上跳


以下這是我們的程式碼:

int finnx=0,finny=500;
int dx=5,bgX=0,bgY=0,jump=0,woodx=0,woody=470;
PImage finn1,finn2,jump1,jump2,bg,bg2,wood,wood1,wood2,wood3;
int onboard=0;  
//--------------------------------------------------------------//宣告所有程式所需要用的圖片
void setup(){
  size(600,800);
  finn1 = loadImage("Finn_right.png");
  finn2 = loadImage("Finn_left.png");
  jump1 = loadImage("jump_right.png");
  jump2 = loadImage("jump_left.png");
  bg = loadImage("sky.jpg");
  bg2= loadImage("bg2.jpg");
  wood  = loadImage("wood.png");
  wood1 = loadImage("wood.png");
  wood2 = loadImage("wood.png");
  wood3 = loadImage("wood.png");
}
//----------------------------------------------------------------
void draw(){
  background (239,228,176);
  image(bg2,0,bgY,600,800); //-------------------<初始背景>
  //----------------------------------------------------------------<背景移動:背景會因為主角移動而延伸
 if(bgY>0){
    image(bg,0,bgY-800,600,800);
  }
  if(bgY-800>0){
    image(bg,0,bgY-1600,600,800);
  }
  if(bgY-1600>0)bgY-=800;
  //----------------------------------------------------------------->
  //-----------------------------------------------------------------<宣告階梯
  image(wood ,woodx+340,woody,350,100);
  if ( finnx>woodx+340 && finnx<woodx+600 && finny <= 400){//如果主角在這個範圍內
        finny = 360;                                       //將會把主角的水平位置往上移
        println("up");
        onboard=1;
       }else{
     onboard=0;
     }
  image(wood1,woodx    ,woody-100,350,100);
  if ( finnx>woodx && finnx<woodx+350 && finny <= 200){
        finny = 220;    
        println("up");
        onboard=1;
       }else{
     onboard=0;
     }
  image(wood2,woodx+200,woody-250,350,100);
  image(wood3,woodx+340,woody-400,350,100);
  //-------------------------------<左右移動
  if (finnx>500 || finnx<0) dx=-dx;//使主角會自動左右移動到兩邊盡頭時會轉身
  finnx+=dx;
  //------------------------------->
  //-------------------------------<向右前進.跳耀
  if(dx>0){
    if(jump>0){
        image(jump1,finnx,finny,100,150);
        jump=jump-10;
        finny-=10;
      }
   
    else image(finn1,finnx,finny,100,150);
    if(finny<500 && onboard==0){
        finny+=5;
      }
    }
  //-------------------------------<向左前進.跳耀
  else {
    if(jump>0){
        image(jump2,finnx,finny,100,150);
        jump=jump-10;
        finny-=10;
      }
    else image(finn2,finnx,finny,100,150);
    if(finny<500 && onboard==0){
        finny+=5;
      }
    }
    /*if ( finnx>woodx+340 && finnx<woodx+600 && finny <= 400){
        finny = 360;    
        println("up");
        onboard=1;
       }else{
     onboard=0;
     }*/
  //------------------------------->

  //-------------------------------<跳躍
  }
  void keyPressed()  {
  if (key==' '){
    jump=300;
   }
 
}
  //------------------------------->\

目前還有些許的BUG
也就是無法上了第二階層後繼續跳躍
我們會繼續修改我們的程式 讓他更完整

Midterm

Midterm 期中作品

1. 執行成果:

遊戲名稱:棒球轟不讓
遊戲方法:登入遊戲畫面點選開始遊戲按鈕,遊戲開始時玩家利用滑鼠搖動以及點擊控制球棒揮動角度,棒球會從投手位置投球出來,要打擊目標物為上方酒瓶,打中會加一分,沒打中不會扣分,時間限制為一分鐘。遊戲結束畫面會依分數有無達到規定跳出成功/失敗畫面。

Demo影片
成果截圖


 遊戲登入畫面點選開始遊戲按鈕(紅箭頭指向處)


 遊戲開始畫面,分別有clock時間軸來記錄時間grade記分板來記錄分數
bat球棒為玩家揮動控制ball棒球會從pitcher投手丟向bat球棒
wine酒瓶為要打擊的目標物


 遊戲結束畫面-闖關成功score分數>13分為遊戲成功


遊戲結束畫面-闖關失敗score分數<12分為遊戲失敗

2. 程式碼:

/*宣告放音樂函式*/
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioPlayer song;
PImage login,gamebg,win,lose,pitcher,bat,ball,wine1,wine2,wine3,clock;
PImage [] num = new PImage [10];
Timer timer,timer2;
int bg=1,s1=0,s2=0,s=0,score=0;
int lastTime=60;  //時間60秒
float wine1x=0,wine2x=100,wine3x=230,wine4x=300,wine5x=450,rect_x=0;
float bangangle=0;
float bx=480,vx=0,nx=0;
float by=150,vy=0,ny=0;
float x,y,a,b;
int state=0,stateBall;
float inner;
void setup() {
  size(640,500);  //視窗大小
  /*放音樂,音樂要儲存在processing檔案資料夾下*/
  minim = new Minim(this);
  song = minim.loadFile("baseball.mp3", 2048);
  /*載入圖片*/
  login = loadImage("login.jpg");
  gamebg = loadImage("gamebg.jpg");
  win = loadImage("win.jpg");
  lose = loadImage("lose.jpg");
  wine1 = loadImage("wine1.gif");
  wine2 = loadImage("wine2.gif");
  wine3 = loadImage("wine3.gif");
  pitcher = loadImage("pitcher.gif");
  ball = loadImage("ball.gif");
  bat = loadImage("bat.gif");
  clock = loadImage("clock.gif"); 
  for(int i=0;i<10;i++){
    num[i]=loadImage(""+i+".jpg");
  }
}
float sx=-3,sy=0.48;//error 1, not local variable
void ball(){  //球棒
   bx=bx+sx; by=by+sy;//error 3, need to modify (bx,by)
   if(bx>0&&state==0){
      //bx=bx+sx; by=by+sy;//error 3, need to modify (bx,by)
     if(bx<=150&&state==0){
       state=1;
       //println("state=1");
     }
      else if(bx<10&&state==0){
        bx+=480; by-=50;
      }
    }  
    if(state==1){
     inner=vx*sx+vy*sy;
      sx=2*(sx-2*inner*vx);
      sy=2*(sy-2*inner*vy);
      print(sx+"\n"+sy+"\n");
      state=2;//error 2, always collision
      stateBall=0;
    }
    if(bx>640||bx<0||by<0||by>448)
    { sx=-1*6+random(1); sy=(94+random(2))/100;
      bx=480; by=150;
      bx=bx+sx; by=by+sy;
      state=0;
    }
  image(ball,bx,by);
  //point(bx+25,by+25); //球棒中心點bx+25,by+25
//  print("bx:"+(bx+25)+" by:"+(by+25)+"\n");
//  print("dx:"+bx+" dy:"+by+"\n");  //球速向量dx,dy
}
void bat(){  //球棒
  pushMatrix();
    translate(150,350);
    rotate(bangangle);
    translate(-17,-180);
    image(bat,0,0,70,200);
    stroke(255,255,0);//Line color
    strokeWeight(10);//line size
    //line(17,0,17,200);//draw line
    stroke(255,0,0);//Line color
    //line(17,50,100,50);//球棒法線
  popMatrix();
  //point(150,350);
 // print("batangel:"+bangangle+"\n"); 
  vx=cos(bangangle);  //球棒向量vx,vy
  vy=sin(bangangle);
 // print("vx:"+vx+" vy:"+vy+"\n");
  nx=-2/vx;  //球棒法向量nx,ny
  ny=1/vy;
 // print("nx:"+nx+" ny:"+ny+"\n");  
  a=tan(bangangle);
  b=350-150*a;   
}
void winemove(){  //酒瓶移動
  if(wine1x<640){
    wine1x+=1;
    if(wine1x==640){
      wine1x-=640;
    }
    if(bx>=wine1x && bx<wine1x+50 && by<100 && stateBall==0)
     { s++; stateBall=1;}
  }
  image(wine1,wine1x,0);  
  if(wine2x<640){
     wine2x+=1;
     if(wine2x==640){
       wine2x-=640;
     }
     if(bx>=wine2x && bx<wine2x+50 && by<100 && stateBall==0)
     { s++; stateBall=1;}
  }
  image(wine2,wine2x,0);  
  if(wine3x<640){
    wine3x+=1;
    if(wine3x==640){
      wine3x-=640;
    }
    if(bx>=wine3x && bx<wine3x+50 && by<100 && stateBall==0)
     { s++; stateBall=1;}
  }
  image(wine3,wine3x,0); 
  if(wine4x<640){
    wine4x+=1;
     if(wine4x==640){
       wine4x-=640;
     }
     if(bx>=wine4x && bx<wine4x+50 && by<100 && stateBall==0)
     { s++; stateBall=1;}
  }
  image(wine1,wine4x,0);
  if(wine5x<640){
    wine5x+=1;
    if(wine5x==640){
      wine5x-=640;
    }
    if(bx>=wine5x && bx<wine5x+50 && by<100 && stateBall==0)
     { s++; stateBall=1;}
  }       
  image(wine2,wine5x,0);
}
void grade(){  //記分板
  s1=s%10; 
  image(num[s1],560,348,60,80); //個位數
  s2=s/10;
  image(num[s2],500,348,60,80); //十位數
}
void clock(){  //時間軸
  noStroke();
  fill(0);
  rect(0,448,640,52);
  image(clock,0,448,40,52);  //起點鐘
  image(clock,600,448,40,52);  //終點鐘
  //bug2-->下排時間軸不準確會有誤差!!(喊一秒)//bug1-->登入畫面時計時器便開始計時了!!
  lastTime=60-millis()/1000;
  if(lastTime>0){
    fill(255);
    rect_x+=0.16;
    rect(43,448,rect_x,600);
  }else if(lastTime<=0){
    fill(255);
    rect(43,448,rect_x,600);
  }
}
void draw() {
  if(bg==1){  //登入遊戲畫面 
     image(login,0,0,640,500);
     if(mousePressed && mouseX>=150 && mouseX<=500 && mouseY>=380 && mouseY<=500){
       image(gamebg,0,0);     
       bg=2;
       //print("進入遊戲\n");
     }
  } 
  if(bg==2){  //遊戲開始畫面
    song.play();  //音樂播放
    image(gamebg,0,0,640,448);
    image(pitcher,450,100);
    winemove();  //酒瓶移動
    grade(); //記分板
    clock();  //時間軸
    ball();   //棒球
    bat();  //球棒
    //print("a=  "+a+"\nb=  "+b+"\n");
    if(lastTime<=0){
      bg=3;
      if(s>=12){
        image(win,0,0,640,448);  //贏畫面
        grade();
      }else if(s<12){
        image(lose,0,0,640,448);  //輸畫面
        grade();
      } 
    }
  }
  //print("ny/nx="+ny/nx+"\n");
}
/*void keyPressed() {
  if (key==' ')  s++;
}*/
void mouseDragged()
{
  bangangle=1/2*PI-mouseX/150.0;  //球棒角度bangangle
}

3. 心得:

在做互動期中作品中遇到許多問題,有些有解決而有些無法如預期結果。我們不斷地努力測試和debug,經由這次期中作品知道自己有許多不足和加強的地方得再接再厲。
以下是遇到的問題與討論:
(1) 時間部分會有小小的誤差,從執行開始的登入畫面時間就開始計時了。
(2) 棒球和球棒部分是這次作品最大的問題,必須考慮球反彈的角度、速度等等,計算棒球和球棒的向量、法向量、斜率等等。這個部份讓我們頭痛好久,雖然還是有不足的地方。謝謝老師不厭其煩地教導。
(3) 程式碼部分寫起來有點混亂,可以再濃縮和整理。






Week09,Midtern


int jx=30;//470
int jy=420;
int jz=3;//速度
PImage img;
PImage img2;
int state=1;
int jump=0;
int savetime;
int score;
int rect1, rect2, rect3, rect4, rect5, rect6, rect7, rect8, rect9, rect10, rect11 ;
int run=70;
int rectx1, rectx2, rectx3, recty1=100, recty2=0, recty3=-100;
int speed = 1;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
void setup() {
  size(750, 500);
  img = loadImage("10.png");
  img2 = loadImage("20.png");
  savetime = millis();
  minim = new Minim(this); 
  //  player = minim.loadFile("dam.mp3");
  //  player.play();
  randomRect();
}
void draw() {
  background(0, 0, 0);
  fill(185, 122, 87);
  rect(10, 70, 530, 420);
  fill(128, 0, 0);
  rect(30, 70, 490, 400);
  fill(0, 255, 255);
  textSize(20);
  text("SCORE", 120, 30);
  fill(128, 255, 128);
  textSize(50);
  text("F", 420, 55);
  fill(255, 255, 0);
  textSize(55);
  text("JUMPER", 550, 45);
  textSize(20);
  text("99161030", 640, 70);
  textSize(20);
  text("99160574", 640, 90);
  textSize(30);
  text("RECORD:", 550, 200);
  fill(128, 255, 128);
  textSize(50);
  text("F", 700, 280);
  fill(0, 255, 255);
  textSize(50);
  text("PAUSE", 570, 400);
  if  (mousePressed && 570<mouseX && mouseX<720 && 360<mouseY && mouseY<400) {
    state*=-1;
  }

  if (state==1) {
    jx+=jz;
    if (jx>=470 || jx<=30) {
      jz*=-1;
    }
  }
  if (jz==3) image(img, jx, jy);
  if (jz==-3) image(img2, jx, jy);

//  if (millis()%1000<30) {  
//    rect1=int(random(1, 12));
//    rect2=int(random(1, 12));
//    rect3=int(random(1, 12));
//    rect4=int(random(1, 12));
//    rect5=int(random(1, 12));
//    rect6=int(random(1, 12));
//    rect7=int(random(1, 12));
//    rect8=int(random(1, 12));
//    rect9=int(random(1, 12));
//    rect10=int(random(1, 12));
//  }
  fill(185, 122, 87); 
 
  recty1 += 1;
  recty2 += 1;
  recty3 += 1;
//  recty4 += 1;
//  recty5 += 1;
//  recty6 += 1;
//  recty7 += 1;
//  recty3 += 1;
//  recty3 += 1;
  rect(rectx1, recty1, 100, 10);
  rect(rectx2, recty2, 100, 10);
  rect(rectx3, recty3, 100, 10);
//   if(rect1==1){  rect(30,run++, 100, 10);  } 
//   if(rect1==2){  rect(70,run++, 100, 10);  } 
//   if(rect1==3){  rect(110,run++, 100, 10);  } 
//   if(rect1==4){  rect(150,run++, 100, 10);  } 
//   if(rect1==5){  rect(190,run++, 100, 10);  } 
//   if(rect1==6){  rect(230,run++, 100, 10);  }
//   if(rect1==7){  rect(270,run++, 100, 10);  }
//   if(rect1==8){  rect(310,run++, 100, 10);  }
//   if(rect1==9){  rect(350,run++, 100, 10);  } 
//   if(rect1==10){  rect(390,run++, 100, 10);  }   
//   if(rect1==11){  rect(420,run++, 100, 10);  }
  textSize(24);
  text(+score, 120, 60);
  int passtime = millis() - savetime;
  int gametime = 20-passtime/1000;
  textSize(24);
  text("TIME: "+gametime, 590, 140);
  if ( gametime <= 0 ) {
    background(0, 0, 0);
    fill(255, 0, 0);
    textSize(40);
    text(" Time's up !! ", 260, 180);
    text(" SCORE : "+score, 240, 330);
  }
  if (jy-30<recty1 && jx>rectx1)  jy=recty1-30;
  if (jy>=420) jy=420;
  println(mouseY);
}
void randomRect() {
  rectx1 = int(random(30, 420));
  rectx2 = int(random(30, 420));
  rectx3 = int(random(30, 420));
}
void keyPressed()
{
  if (key==' ') {
    jy-=80;
    score=score+=10;
  }
}


還需要改進的部分有: (1)一開始長方體為固定人物漸漸往上跳,鏡頭也可以漸漸帶上去,接連下來有隨機的長方體 (2)每爬上一定的距離FLOOR就會慢慢增加並顯示出來 (3)會留下最高紀錄

Midterm

1.音樂以放入
2.未來加強
1.增加預備出現拍子的前置圖片
2.改善目前介面的美工
3.增加斷連段
4.遊戲音樂結速和開始
5.可能增加音樂譜面





import ddf.minim.*;
Minim minim; 
AudioPlayer bgm;
boolean a1=false;
boolean a12=false;
boolean s1=false;
boolean s12=false;
boolean d1=false;
boolean f1=false;
boolean z1=false;
boolean x1=false;
boolean c1=false;
boolean v1=false;
boolean y1=false;
boolean u1=false;
boolean i1=false;
boolean o1=false;
boolean h1=false;
boolean j1=false;
boolean k1=false;
boolean l1=false;
boolean q1=false;
boolean d12=false;
boolean f12=false;
boolean z12=false;
boolean x12=false;
boolean c12=false;
boolean v12=false;
boolean y12=false;
boolean u12=false;
boolean i12=false;
boolean o12=false;
boolean h12=false;
boolean j12=false;
boolean k12=false;
boolean l12=false;
boolean q12=false;
boolean take=false;
int s123=0;
 int sice=0;
 int siceten=0;
 int sicehun=0;
 int m=0;
void setup(){
  size(600,650);
   minim = new Minim(this);
  bgm = minim.loadFile("aas.mp3");
  bgm.play();
}
void sicetake()//////////////////// 計分判斷
{
 if(sice<10)
    {
    sice++;
    }
    if(sice==10)
    {
      sice=0;
      if(siceten<10)
      {
      siceten++;
      }
      if(siceten==10)
      {
        siceten=0;
        if(sicehun<10)
        {
          sicehun++;
        }
      }
      }
          s123=0;
}
void draw()
{
  ////////////////////////////////顯示記分判斷
   if(s1==true&&s12==true)
  {
    sicetake();
    s12=false;
  }
   else if(a1==true&&a12==true)
  {
    sicetake();
    a12=false;
  }
     else if(d1==true&&d12==true)
  {
    sicetake();
    d12=false;
  }
    else if(f1==true&&f12==true)
  {
    sicetake();
    f12=false;
  }
     else if(z1==true&&z12==true)
  {
    sicetake();
    z12=false;
  }
     else if(x1==true&&x12==true)
  {
    sicetake();
    x12=false;
  }
     else if(c1==true&&c12==true)
  {
    sicetake();
    c12=false;
  }
       else if(v1==true&&v12==true)
  {
    sicetake();
    v12=false;
  }
       else if(y1==true&&y12==true)
  {
    sicetake();
    y12=false;
  }
       else if(u1==true&&u12==true)
  {
    sicetake();
    u12=false;
  }
       else if(i1==true&&i12==true)
  {
    sicetake();
    i12=false;
  }
       else if(o1==true&&o12==true)
  {
    sicetake();
    o12=false;
  }
       else if(h1==true&&h12==true)
  {
    sicetake();
    h12=false;
  }
       else if(j1==true&&j12==true)
  {
    sicetake();
    j12=false;
  }
       else if(k1==true&&k12==true)
  {
    sicetake();
    k12=false;
  }
       else if(l1==true&&l12==true)
  {
    sicetake();
    l12=false;
  }
  ///////////////////////////////////////////////////
  background(255);
  
  int m = millis()/1000;

   if(m==1)
  {
  }
  if(m==2)
  {
  }
  if(m==3)
  {
  a1=true;
  s1=true;
  }
  if(m==4)
  {
    a1=false;
    s1=false;
  }
    if(m==5)
  {
    h1=true;
  }
   if(m==6)
  {
    h1=false;
  }
   if(m==7)
  {
  j1=true;
  h1=true;
  }
   if(m==8)
  {
    j1=false;
    h1=false;
  }
   if(m==9)
  {
    d1=true;
  }
   if(m==10)
  {
    d1=false;
    c1=true;
  }
    if(m==11)
  {
    c1=false;
  }
  if(m==12)
  {
    a1=true;
  }
  if(m==13)
  {
    s1=true;
    a1=false;
  }
  if(m==14)
  {
    d1=true;
    s1=false;
  }
    if(m==15)
  {
     f1=true;
     d1=false;
  }
   if(m==16)
  {
    v1=true;
    f1=false;
  }
   if(m==17)
  {
    c1=true;
    v1=false;
  }
   if(m==18)
  {
    x1=true;
    c1=false;
  }
   if(m==19)
  {
    z1=true;
    x1=false;
  }
   if(m==20)
  {
    y1=true;
    z1=false;
  }
     if(m==21)
  {
    u1=true;
    y1=false;
  }
  if(m==22)
  {
    i1=true;
    u1=false;
  }
  if(m==23)
  {
    o1=true;
    i1=false;
  }
  if(m==24)
  {
    l1=true;
    o1=false;
  }
    if(m==25)
  {
   k1=true;
   l1=false;
  }
   if(m==26)
  {
   j1=true;
   k1=false;
  }
   if(m==27)
  {
  h1=true;
  j1=false;
  }
   if(m==28)
  {
    h1=false;
    a1=true;
   
  }
   if(m==29)
  {
    z1=true;
     a1=false;
  }
   if(m==30)
  {
   y1=true;
    z1=false;
  }
     if(m==31)
  {
    h1=true;
    y1=false;
  }
  if(m==32)
  {
     h1=false;
  }
  if(m==33)
  {
  }
  if(m==34)
  {
  }
    if(m==35)
  {
  }
   if(m==36)
  {
  }
   if(m==37)
  {
  }
   if(m==38)
  {
  }
   if(m==39)
  {
  }
   if(m==40)
  {
  }
 
 fill(255);
 /////////////////////////////////////////////第一排
 rect(50, 100, 100, 100);    
 rect(180, 100, 100, 100);
 rect(310, 100, 100, 100);
 rect(440, 100, 100, 100);
 ///////////////////////////////////////////////第二排
 rect(50, 230, 100, 100);
 rect(180, 230, 100, 100);
 rect(310, 230, 100, 100);
 rect(440, 230, 100, 100);
 //////////////////////////////////////////////第三排
 rect(50, 360, 100, 100);
 rect(180, 360, 100, 100);
 rect(310, 360, 100, 100);
 rect(440, 360, 100, 100);
 //////////////////////////////////////////////第四排
 rect(50, 490, 100, 100);
 rect(180, 490, 100, 100);
 rect(310, 490, 100, 100);
 rect(440, 490, 100, 100);
 /////////////////////////////////////////////////////////
  if(a1)
  {
    fill(0);
    rect(50, 100, 100, 100);
  }
   if(s1)
  {
    fill(0);
    rect(180, 100, 100, 100);
  }
   if(d1)
  {
    fill(0);
      rect(310, 100, 100, 100);
  }
   if(f1)
  {
    fill(0);
     rect(440, 100, 100, 100); 
  }
/////////////////////////////////////////////////////第一排
   if (z1)
        {
      fill(0);
      rect(50, 230, 100, 100);
        }
     if(x1)
        {
      fill(0);
      rect(180, 230, 100, 100);  
         
        }
      if(c1)
        {
      fill(0);
      rect(310, 230, 100, 100);      
        }
      if(v1)
        {
      fill(0);
      rect(440, 230, 100, 100);      
        }
//////////////////////////////////////////第二排
   if (y1)
        {
      fill(0);
      rect(50, 360, 100, 100);
        }
   if(u1)
        {
      fill(0);
      rect(180, 360, 100, 100);           
        }
      if(i1)
        {
      fill(0);
      rect(310, 360, 100, 100);      
        }
      if(o1)
        {
      fill(0);
      rect(440, 360, 100, 100);      
        }
/////////////////////////////////////////////////////////////第三排
if (h1)
        {
      fill(0);
      rect(50, 490, 100, 100);
        }
     if(j1)
        {
      fill(0);
      rect(180, 490, 100, 100);  
         
        }
      if(k1)
        {
      fill(0);
      rect(310, 490, 100, 100);      
        }
      if(l1)
        {
      fill(0);
      rect(440, 490, 100, 100);      
        }
 
////////////////////////////////////////////////////////////////第四排////////////X+50.Y+80
if(sice==1)
 {
  fill(0,0,0,120);
 rect(450, 280, 20, 60);
 rect(450, 360, 20, 60);
 }
 if(siceten==1)
 {
  fill(0,0,0,120);
 rect(300, 280, 20, 60);
 rect(300, 360, 20, 60);
 }
 if(sicehun==1)
 {
  fill(0,0,0,120);
 rect(150, 280, 20, 60);
 rect(150, 360, 20, 60);
 }
if(siceten==2)
 {
  fill(0,0,0,120);
 rect(240,260,60,20);
 rect(300, 280, 20, 60);
 rect(240,340,60,20);
 rect(220, 360, 20, 60);
 rect(240,420,60,20);
 }
if(sicehun==2)
 {
  fill(0,0,0,120);
 rect(90,260,60,20);
 rect(150, 280, 20, 60);
 rect(90,340,60,20);
 rect(70, 360, 20, 60);
 rect(90,420,60,20);
 }
if(sice==2)
 {
  fill(0,0,0,120);
 rect(390,260,60,20);
 rect(450, 280, 20, 60);
 rect(390,340,60,20);
 rect(370, 360, 20, 60);
 rect(390,420,60,20);
 }
if(sice==3)
 {
  fill(0,0,0,120);
 rect(390,260,60,20);
 rect(450, 280, 20, 60);
 rect(390,340,60,20);
 rect(450, 360, 20, 60);
 rect(390,420,60,20);
 }
if(siceten==3)
 {
  fill(0,0,0,120);
 rect(240,260,60,20);
 rect(300, 280, 20, 60);
 rect(240,340,60,20);
 rect(300, 360, 20, 60);
 rect(240,420,60,20);
 }
if(sicehun==3)
 {
  fill(0,0,0,120);
 rect(90,260,60,20);
 rect(150, 280, 20, 60);
 rect(90,340,60,20);
 rect(150, 360, 20, 60);
 rect(90,420,60,20);
 }
 if(sice==4)
 {
   fill(0,0,0,120);
   rect(370, 280, 20, 60);
   rect(450, 280, 20, 60);
   rect(390,340,60,20);
   rect(450, 360, 20, 60);
 }
 if(siceten==4)
 {
   fill(0,0,0,120);
   rect(220, 280, 20, 60);
   rect(300, 280, 20, 60);
   rect(240,340,60,20);
   rect(300, 360, 20, 60);
 }
 if(sicehun==4)
 {
   fill(0,0,0,120);
   rect(70, 280, 20, 60);
   rect(150, 280, 20, 60);
   rect(90,340,60,20);
   rect(150, 360, 20, 60);
 }
 if(sice==5)
 {
 fill(0,0,0,120);
 rect(390,260,60,20);
 rect(370, 280, 20, 60);
 rect(390,340,60,20);
 rect(450, 360, 20, 60);
 rect(390,420,60,20);
 }
 if(siceten==5)
 {
 fill(0,0,0,120);
 rect(240,260,60,20);
 rect(220, 280, 20, 60);
 rect(240,340,60,20);
 rect(300, 360, 20, 60);
 rect(240,420,60,20);
 }
 if(sicehun==5)
 {
 fill(0,0,0,120);
 rect(90,260,60,20);
 rect(70, 280, 20, 60);
 rect(90,340,60,20);
 rect(150, 360, 20, 60);
 rect(90,420,60,20);
 }
  if(sice==6)
 {
 fill(0,0,0,120);
 rect(390,260,60,20);
 rect(450, 280, 20, 60);
 rect(390,340,60,20);
 rect(450, 360, 20, 60);
 rect(390,420,60,20);
 rect(370, 360, 20, 60);
 }
 if(siceten==6)
 {
 fill(0,0,0,120);
 rect(240,260,60,20);
 rect(300, 280, 20, 60);
 rect(240,340,60,20);
 rect(300, 360, 20, 60);
 rect(240,420,60,20);
 rect(220, 360, 20, 60);
 }
 if(sicehun==6)
 {
 fill(0,0,0,120);
 rect(90,260,60,20);
 rect(150, 280, 20, 60);
 rect(90,340,60,20);
 rect(150, 360, 20, 60);
 rect(90,420,60,20);
 rect(70, 360, 20, 60);
 }
 if(sice==7)
 {
 fill(0,0,0,120);
 rect(390,260,60,20);
 rect(450, 280, 20, 60);
 rect(450, 360, 20, 60);
 }
 if(siceten==7)
 {
 fill(0,0,0,120);
 rect(240,260,60,20);
 rect(300, 280, 20, 60);
 rect(300, 360, 20, 60);
 }
 if(sicehun==7)
 {
 fill(0,0,0,120);
 rect(90,260,60,20);
 rect(150, 280, 20, 60);
 rect(150, 360, 20, 60);
 }
 if(sice==8)
 {
 fill(0,0,0,120);
 rect(390,260,60,20);
 rect(450, 280, 20, 60);
 rect(390,340,60,20);
 rect(450, 360, 20, 60);
 rect(390,420,60,20);
 rect(370, 360, 20, 60);
 rect(370, 280, 20, 60);
 }
 if(siceten==8)
 {
 fill(0,0,0,120);
 rect(240,260,60,20);
 rect(300, 280, 20, 60);
 rect(240,340,60,20);
 rect(300, 360, 20, 60);
 rect(240,420,60,20);
 rect(220, 360, 20, 60);
 rect(220, 280, 20, 60);
 }
 if(sicehun==8)
 {
 fill(0,0,0,120);
 rect(90,260,60,20);
 rect(150, 280, 20, 60);
 rect(90,340,60,20);
 rect(150, 360, 20, 60);
 rect(90,420,60,20);
 rect(70, 360, 20, 60);
 rect(70, 280, 20, 60);
 }
 if(sice==9)
 {
 fill(0,0,0,120);
 rect(390,260,60,20);
 rect(450, 280, 20, 60);
 rect(390,340,60,20);
 rect(450, 360, 20, 60);
 rect(390,420,60,20);
// rect(320, 280, 20, 60);
 rect(370, 280, 20, 60);
 }
 if(siceten==9)
 {
 fill(0,0,0,120);
 rect(240,260,60,20);
 rect(300, 280, 20, 60);
 rect(240,340,60,20);
 rect(300, 360, 20, 60);
 rect(240,420,60,20);
// rect(320, 280, 20, 60);
 rect(220, 280, 20, 60);
 }
 if(sicehun==9)
 {
 fill(0,0,0,120);
 rect(90,260,60,20);
 rect(150, 280, 20, 60);
 rect(90,340,60,20);
 rect(150, 360, 20, 60);
 rect(90,420,60,20);
// rect(320, 280, 20, 60);
 rect(70, 280, 20, 60);
 }
 if(sice==0)
 {
 fill(0,0,0,120);
 rect(390,260,60,20);
 rect(450, 280, 20, 60);
// rect(390,340,60,20);
 rect(450, 360, 20, 60);
 rect(390,420,60,20);
 rect(370, 360, 20, 60);
 rect(370, 280, 20, 60);
 }
 if(siceten==0)
 {
 fill(0,0,0,120);
 rect(240,260,60,20);
 rect(300, 280, 20, 60);
// rect(390,340,60,20);
 rect(300, 360, 20, 60);
 rect(240,420,60,20);
 rect(220, 360, 20, 60);
 rect(220, 280, 20, 60);
 }
 if(sicehun==0)
 {
 fill(0,0,0,120);
 rect(90,260,60,20);
 rect(150, 280, 20, 60);
// rect(390,340,60,20);
 rect(150, 360, 20, 60);
 rect(90,420,60,20);
 rect(70, 360, 20, 60);
 rect(70, 280, 20, 60);
 }
}
void keyPressed(){
  if(key=='a'|| key == 'A'){
    a12=true;
  }
 else  if(key=='s'|| key == 'S'){
    s12=true;
  }
 else  if(key=='d'|| key == 'D')
{
  d12=true;
}
  else if(key=='f'|| key == 'F')
{
  f12=true;
}
  if(key=='z'|| key == 'Z'){
    z12=true;
  }
 else  if(key=='x'|| key == 'X'){
    x12=true;
  }
 else  if(key=='c'|| key == 'C')
{
  c12=true;
}
  else if(key=='v'|| key == 'V')
{
  v12=true;
}
  if(key=='y'|| key == 'Y'){
    y12=true;
  }
 else  if(key=='u'|| key == 'U'){
    u12=true;
  }
 else  if(key=='i'|| key == 'I')
{
  i12=true;
}
  else if(key=='o'|| key == 'O')
{
  o12=true;
}
  if(key=='h'|| key == 'H'){
    h12=true;
  }
 else  if(key=='j'|| key == 'J'){
    j12=true;
  }
 else  if(key=='k'|| key == 'K')
{
  k12=true;
}
  else if(key=='l'|| key == 'L')
{
  l12=true;
}
else if(key=='q'|| key == 'Q')/////////////////////////////////開始建
{
  q12=true;
}
}
void keyReleased(){
  if(key=='a'|| key == 'A')
  {
    a12=false;
  }
    if(key=='s'|| key == 'S'){
    s12=false;
    s123=3;
  }
   if(key=='d'|| key == 'D')
{
   d12=false;
}
 else  if(key=='f'|| key == 'F')
{
    f12=false;
}
   else if(key=='z'|| key == 'Z')
  {
    z12=false;
  }
   if(key=='x'|| key == 'X'){
    x12=false;
  }
   if(key=='c'|| key == 'C')
{
   c12=false;
}
  else if(key=='v'|| key == 'V')
{
    v12=false;
}
  if(key=='y'|| key == 'Y'){
    y12=false;
  }
 else  if(key=='u'|| key == 'U'){
    u12=false;
  }
 else  if(key=='i'|| key == 'I')
{
  i12=false;
}
  else if(key=='o'|| key == 'O')
{
  o12=false;
}
  if(key=='h'|| key == 'H'){
    h12=false;
  }
 else  if(key=='j'|| key == 'J'){
    j12=false;
  }
 else  if(key=='k'|| key == 'K')
{
  k12=false;
}
  else if(key=='l'|| key == 'L')
{
  l12=false;
}
  else if(key=='q'|| key == 'Q')/////////////////////////開始建
{
  q12=false;
}
}

Week06 , Hw06

 我覺得傅建國的小朋友上樓梯讓我比較期待
因為之前比較常玩小朋友下樓梯,而且在我印象當中都是用手機的方式玩


還有
詹中豪那組的俄羅斯方塊也很勾起我小時的後回憶
感覺他會研發更另類的玩法



我們想做的是“海綿寶寶戳泡泡”

需要
1.海綿寶寶圖案
2.泡泡圖案
3.海底世界背景圖
4.計時,計分器

今天有把基本的架構都做出來,泡泡會動了

期中作品

這是以乒乓球為概念做成的遊戲

而且可以兩個人一起玩

增加朋友間的互動~

圖1


如圖1,左右兩方的藍色條槓為玩家控制,黃色的為球

左方玩家用w、s鍵控制上下移動,右方則↑↓鍵控制



圖2
 
 
 
最上方的紅色部分為雙方的得分數,
且遊戲中上下邊的黑色線條為牆壁
碰到可以反彈
 
 
 


int ballSize = 15;


float ballX;

float ballY;

float ballSpeedX;

float ballSpeedY;

int padding = 25;

int paddleH = 50;

float paddleSpeedY = 3;

float paddleLePosY;

float paddleLeSpeedY = 0;

float paddleRiPosY;

float paddleRiSpeedY = 0;

int scoreLe = 0;

int scoreRi = 0;

void setup() {

size(480, 360);

background(0);

ballX = width/2;

ballY = height/2;

ballSpeedX = 3;

paddleLePosY = height/2-paddleH/2;

paddleRiPosY = height/2-paddleH/2;

}

void draw() {

if (ballX &rt;= width || ballX <= 0 ) {

if ( ballX &rt;= width ) {

scoreLe += 1;

    } 

 else {

scoreRi += 1;

    }

    ballX =  width/2;

    ballY = height/2;

    ballSpeedY = 0;

    paddleLePosY = height/2 - paddleH/2;

    paddleRiPosY = height/2 - paddleH/2;

  }

  noStroke();

  fill(235,168,50);

  rectMode(CORNER);

  rect(0, 0, width, height);

  stroke(100);

  line(padding, padding, width-padding, padding);

  line(padding, height-padding, width-padding, height-padding);

  line(width/1, padding, width/1, height-padding);

  fill(255,0,0);

  textAlign(LEFT);

  text(scoreLe,padding, padding-10); 

  textAlign(RIGHT);

  text(scoreRi, width-padding, padding-10);

  paddleLePosY += paddleLeSpeedY;

  if (paddleLePosY < padding) {

    paddleLePosY = padding;

  } 

  else if (paddleLePosY+paddleH &rt; height-padding) {

    paddleLePosY = height-padding-paddleH;

  }

  paddleRiPosY += paddleRiSpeedY;

  if (paddleRiPosY < padding) {

    paddleRiPosY = padding;

  } 

  else if (paddleRiPosY+paddleH &rt; height-padding) {

    paddleRiPosY = height-padding-paddleH;

  }

  noStroke();

  fill(0,128,255);

  rectMode(CORNER);

  rect(padding, paddleLePosY, 10, paddleH);

  rect(width-padding, paddleRiPosY, 10, paddleH);

  ballX += ballSpeedX;

  ballY += ballSpeedY;

  if ( ballY-ballSize/2 < padding || ballY+ballSize/2 &rt; height-padding ) {

    ballSpeedY *= -1;

  }

  if (ballX-ballSize/2 <= padding && ballX+ballSize/2 &rt; padding) {

    if (ballY &rt;= paddleLePosY && ballY <= paddleLePosY+paddleH) {

      ballSpeedX *= -1;

      float hit = ballY - (paddleLePosY+paddleH/2);

      ballSpeedY += (hit / (paddleH/2)) *2; // range -1 to 1 (*2)

    }

  }

  if (ballX+ballSize/2 &rt;= width-padding && ballX-ballSize/2 < width-padding) {

    if (ballY &rt;= paddleRiPosY && ballY <= paddleRiPosY+paddleH) {

      ballSpeedX *= -1; 

      float hit = ballY - (paddleRiPosY+paddleH/2);

      ballSpeedY += (hit / (paddleH/2)) *2; // range -1 to 1 (*2)

    }

  }

  noStroke();

  fill(255,255,0);

  rectMode(CENTER);

  rect(ballX, ballY, ballSize, ballSize);

}

void keyPressed() {

  if (key == 'w' || key == 'W') {

    paddleLeSpeedY = paddleSpeedY * -1;

  } 

  else if (key == 's' || key == 'S') {

    paddleLeSpeedY = paddleSpeedY;

  } 

  else if (keyCode == UP) {

    paddleRiSpeedY = paddleSpeedY * -1;

  } 

  else if (keyCode == DOWN) {

    paddleRiSpeedY = paddleSpeedY;

  }

}

void keyReleased() {

  if (key == 'w' || key == 'W' || key == 's' || key == 'S') {

    paddleLeSpeedY = 0;

  } 

  else if (keyCode == UP || keyCode == DOWN) {

    paddleRiSpeedY = 0;

  }

}

Midterm



1.貼圖







2.程式碼
PImage tt0,tt1,tt2;
float  bangAngle;
int startT=0;
int value = 0;
int score=0, lastTime=60;
PImage img1,big,img2;
int now=1;

import ddf.minim.*;
AudioPlayer  player,aaa,cheers;
Minim minim;


int a=231,b=204,c=185 ;
int b1=204,c1=185 ;
int b2=204,c2=185 ;
int b3=204,c3=185 ;
int b4=204,c4=185 ;
int b5=204,c5=185 ;
int b6=204,c6=185 ;


void setup(){
  size(500,500);
  
  tt0=loadImage("tt0.png");
  tt1=loadImage("tt1.png");
  tt2=loadImage("tt2.png");
  img1=loadImage("b1.png");
  big=loadImage("big.png");
  img2=loadImage("gameover.png");
}

void show1(){
image(img1,0,0);
}
void show2(){
image(big,0,0);
}
void show3(){
image(img2,0,0);
}

void draw()
{
  

  
  fill(value);
  rect(100, 100, 100, 100);
      
  
 size(500,500);
  int m=millis();
  background(255,255,255);
  image(big,0,0,500,500);


textSize(30);
fill(m/10%10,m/10%10,m/10%255);
text("Time:"+lastTime, 10,40);
text("Score:"+score, 330,40);
if(lastTime&rt;0)
lastTime=60-millis()/1000;
else
lastTime=0;

b-=3;c-=3;
b1-=2;c1-=2;
b2-=0.1;c2-=0.1;
b3-=6;c3-=6;
b4-=7;c4-=7;
b5-=4;c5-=4;
b6-=5;c6-=5;

noStroke();
fill(a,b,c);
ellipse(300,300,20,20);

noStroke();
fill(a,b,c);
ellipse(200,130,20,20);

noStroke();
fill(a,b1,c1);
ellipse(360,230,20,20);




noStroke();
fill(a,b2,c2);
ellipse(192,270,20,20);



noStroke();
fill(a,b3,c3);
ellipse(170,190,10,10);

noStroke();
fill(a,b4,c4);

ellipse(150,160,18,18);

noStroke();
fill(a,b5,c5);
ellipse(130,210,30,30);

noStroke();
fill(a,b6,c6);
ellipse(220,250,20,20);

noStroke();
fill(a,b1,c1);
ellipse(240,150,17,17);

noStroke();
fill(a,b2,c2);
ellipse(300,190,20,20);

noStroke();
fill(a,b4,c4);
ellipse(280,260,30,30);

noStroke();
fill(a,b5,c5);
ellipse(270,390,10,10);

noStroke();
fill(a,b6,c6);
ellipse(235,330,30,30);

noStroke();
fill(a,b,c);
ellipse(150,370,20,20);

noStroke();
fill(a,b1,c1);
ellipse(100,250,15,15);

noStroke();
fill(a,b2,c2);
ellipse(300,300,20,20);

noStroke();
fill(a,b3,c3);
ellipse(350,350,30,30);


  if (b<0    )
{ b=255; c=255;}
  if (b1<0   )
{ b1=255; c1=255;}
  if (b2==0   )
{ b2=255; c2=255;}
  if (b3<0   )
{  b3=255; c3=255;} 
  if (b4<0   )
{  b4=255; c4=255;}
  if (b5<0   )
{  b5=255; c5=255;}
  if (b6<0   )
{  b6=255; c6=255;}







if(mouseX&rt;290 && mouseX < 310 && mouseY&rt;290 && mouseY<310 && mousePressed)image(tt2,290,280,30,30);//又嘴


else if(mouseX&rt;190 && mouseX < 210 && mouseY&rt;120 && mouseY<140 && mousePressed)image(tt2,190,115,30,30);//額頭
else if(mouseX&rt;350 && mouseX < 370 && mouseY&rt;220 && mouseY<240 && mousePressed)image(tt2,350,210,30,30);//右邊
else if(mouseX&rt;180 && mouseX < 200 && mouseY&rt;260 && mouseY<280 && mousePressed)image(tt2,180,250,30,30);//左

else if(mouseX&rt;160 && mouseX < 180 && mouseY&rt;180 && mouseY<200 && mousePressed)image(tt2,160,180,20,20);
else if(mouseX&rt;140 && mouseX < 160 && mouseY&rt;150 && mouseY<170 && mousePressed)image(tt2,140,145,25,25);
else if(mouseX&rt;120 && mouseX < 140 && mouseY&rt;200 && mouseY<220 && mousePressed)image(tt2,115,185,45,45);
else if(mouseX&rt;210 && mouseX < 230 && mouseY&rt;240 && mouseY<260 && mousePressed)image(tt2,210,235,27,27);
else if(mouseX&rt;230 && mouseX < 250 && mouseY&rt;140 && mouseY<150 && mousePressed)image(tt2,230,140,26,26);
else if(mouseX&rt;290 && mouseX < 310 && mouseY&rt;180 && mouseY<200 && mousePressed)image(tt2,290,180,25,25);
else if(mouseX&rt;270 && mouseX < 290 && mouseY&rt;250 && mouseY<270 && mousePressed)image(tt2,260,235,45,45);
else if(mouseX&rt;260 && mouseX < 280 && mouseY&rt;380 && mouseY<400 && mousePressed)image(tt2,260,380,17,17);
else if(mouseX&rt;220 && mouseX < 245 && mouseY&rt;320 && mouseY<340 && mousePressed)image(tt2,220,300,49,49);
else if(mouseX&rt;140 && mouseX < 160 && mouseY&rt;360 && mouseY<380 && mousePressed)image(tt2,140,350,30,30);
else if(mouseX&rt;90 && mouseX < 110 && mouseY&rt;240 && mouseY<260 && mousePressed)image(tt2,90,235,26,26);
else if(mouseX&rt;290 && mouseX < 310 && mouseY&rt;290 && mouseY<310 && mousePressed)image(tt2,290,290,30,30);
else if(mouseX&rt;340 && mouseX < 360 && mouseY&rt;340 && mouseY<360 && mousePressed)image(tt2,325,325,41,41);





  if(now==1){
  show1();
  if(mouseX&rt;200 && mouseX<330 && mouseY&rt;300 && mouseY<430 && mousePressed){
    now=2;
    }
  }
  
  
  if(lastTime==0) //當時間=0,秀出得分
      {
      stop();
       show3();
      textFont(createFont("Calibri", 40));
      fill(128,0,0);
      text("Your score:"+score,150,300);
     // cheers=minim.loadFile("cheers.wav", 2048);
      //cheers.play();
      }
  
  
  
 

}

void mousePressed()
{
  if ( mouseX&rt;180 && mouseX < 200 && mouseY&rt;260 && mouseY<280) 
  {   value = 255;  score+=10;
 
   minim=new Minim(this);
   aaa=minim.loadFile("aaa.wav", 2048); //戳到泡泡時播放音效
   aaa.play();  } 
  
  else if (mouseX&rt;350 && mouseX < 370 && mouseY&rt;220 && mouseY<240) 
  {   value = 255;  score+=10; 
   
   minim=new Minim(this);
   aaa=minim.loadFile("aaa.wav", 2048); //戳到泡泡時播放音效
   aaa.play();
  }
  
  else if (mouseX&rt;190 && mouseX < 210 && mouseY&rt;120 && mouseY<140) 
  {   value = 255;  score+=10; 
 
   minim=new Minim(this);
   aaa=minim.loadFile("aaa.wav", 2048); //戳到泡泡時播放音效
   aaa.play();
  }
  
  else if (mouseX&rt;290 && mouseX < 310 && mouseY&rt;290 && mouseY<310) 
  {   value = 255;  score+=10;

  minim=new Minim(this);
   aaa=minim.loadFile("aaa.wav", 2048); //戳到泡泡時播放音效
   aaa.play();
  }
  
  
  
  
  
  else if (mouseX&rt;160 && mouseX < 180 && mouseY&rt;180 && mouseY<200) 
  {   value = 255;  score+=100;
    minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;140 && mouseX < 160 && mouseY&rt;150 && mouseY<170) 
  {   value = 255;  score+=10;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;120 && mouseX < 140 && mouseY&rt;200 && mouseY<220) 
  {   value = 255;  score+=1;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;210 && mouseX < 230 && mouseY&rt;240 && mouseY<260) 
  {   value = 255;  score+=10;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;230 && mouseX < 250 && mouseY&rt;140 && mouseY<150) 
  {   value = 255;  score+=10;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;290 && mouseX < 310 && mouseY&rt;180 && mouseY<200) 
  {   value = 255;  score+=10;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;270 && mouseX < 290 && mouseY&rt;250 && mouseY<270) 
  {   value = 255;  score+=1;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;260 && mouseX < 280 && mouseY&rt;380 && mouseY<400) 
  {   value = 255;  score+=100;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;220 && mouseX < 245 && mouseY&rt;320 && mouseY<340) 
  {   value = 255;  score+=1;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;90 && mouseX < 110 && mouseY&rt;240 && mouseY<260) 
  {   value = 255;  score+=10;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;140 && mouseX < 160 && mouseY&rt;360 && mouseY<380) 
  {   value = 255;  score+=10;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;290 && mouseX < 310 && mouseY&rt;290 && mouseY<310) 
  {   value = 255;  score+=10;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  else if (mouseX&rt;340 && mouseX < 360 && mouseY&rt;340 && mouseY<360) 
  {   value = 255;  score+=1;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
  
  else  { value = 0; score-=50;  
 minim=new Minim(this);aaa=minim.loadFile("aaa.wav", 2048);aaa.play();}
 
}

3.遊戲規則


點到痘痘就可得分


大顆1分


小顆100分


點到臉扣50分


點到痘痘會有"啵~"的聲音


限時60秒


時間歸零即遊戲結束



4.心得


完成一個作品蠻有成就感的,雖然沒有做到很完美,但是一步步寫出來,遇到問題一起討論然後解決他,感覺真的有學到東西。

期中小專題--拋雞蛋

1, 遊戲設計:
雞蛋拋拋樂
一開雞蛋在最下面的籃子,
只要按滑鼠右鍵,便能使雞蛋向上拋,
拋到籃子裡則得一分,到外面則直接結束遊戲 : D

一旦雞蛋在中間籃子準備往最上面的籃子拋時,
雞蛋進到最上面的籃子則籃子會自動往下移一格,
然後最上面產生新的籃子;
若是從中間的籃子往上拋到最上面的籃子失敗時,
則遊戲直接結束。

2, 程式碼:
import ddf.minim.*;
AudioPlayer player;
Minim ponyo;

int score1=0, a=0, b=0, c=0, d=0, s=0;
PImage Background;  //背景
PImage life;  //生命值小雞
PImage die;  //死小雞
PImage egg;  //雞蛋
PImage score;  //"分數"字樣
PImage num[] = new PImage[10];  //分數數字0-9
PImage over;

//籃子
PImage basket1;
PImage basket2;
PImage basket3;
float e=random(3)+1, f=random(3)+1, g=random(3)+1; //速度
float b1X=random(420)+90, b2X=random(420)+90, b3X=random(420)+90;  //籃子原X座標
float b1Y=650, b2Y=450, b3Y=250;  //籃子原Y座標
float eX=285, eY=640;  //雞蛋原座標

float w=0;
int sw=0;

void mouseClicked() {
  w=1;
  sw=1;
  if(eY&rt;250)
  eY-=200;
  score1+=1;
}

void setup() {
  ponyo = new Minim(this);
  player = ponyo.loadFile("Ponyo.mp3", 2048);
  player.play();
  
  size(600, 700);
  Background = loadImage("background_sky.png");
  life = loadImage("life.png");
  die = loadImage("die.png");
  score = loadImage("score.png");
  for (int i=0;i<10;i++)
  {
    num[i]=loadImage(i+".png");
  }
  egg = loadImage("egg.png");

  basket1 = loadImage("basket.png");
  basket2 = loadImage("basket.png");
  basket3 = loadImage("basket.png");
  
  over = loadImage("game-over.png");
}

void draw() {
  //背景
  image(Background, 0, 0, 600, 900);
  

  //雞蛋
  image(egg, eX, eY, 40, 50);
  //籃子
  image(basket1, b1X, b1Y, 90, 50);
  b1X+= e;
  if (sw==0) eX=b1X+25;
  if (b1X&rt;510) {b1X=510;e*=-1;}
  if (b1X<0) {b1X=0;e*=-1;}
  image(basket2, b2X, b2Y, 90, 50);
  b2X+= f;
  if (b2X&rt;510) {b2X=510;f*=-1;}
  if (b2X<0) {b2X=0;f*=-1;}
  image(basket3, b3X, b3Y, 90, 50);
  b3X+= g;
  if (b3X&rt;510) {b3X=510;g*=-1;}
  if (b3X<0) {b3X=0;g*=-1;}
//==============================
  if (b1Y==450 && eX<b1X+45 && eX&rt;b1X-45 && eY<475 && eY&rt;425) {
    //雞蛋位置
    eY=b1Y;
    eX=b1X+25;
  }else if (b2Y==450 && eX<b2X+45 && eX&rt;b2X-45 && eY<475 && eY&rt;425) {
    //雞蛋位置
    eY=b2Y;
    eX=b2X+25;
  }else if (b3Y==450 && eX<b3X+45 && eX&rt;b3X-45 && eY<475 && eY&rt;425) {
    //雞蛋位置
    eY=b3Y;
    eX=b3X+25;
  }else if(b1Y== 250 && eX<b1X+45 && eX&rt;b1X-45 && eY<275 && eY&rt;225){
    eY=b1Y;
    eX=b1X+25;
    w=b2Y;
    b2Y=b1Y;
    b1Y=b3Y;
    b3Y=w;
    eY+=200;
  }else if(b2Y== 250 && eX<b2X+45 && eX&rt;b2X-45 && eY<275 && eY&rt;225){
    eY=b2Y;
    eX=b2X+25;
    w=b2Y;
    b2Y=b1Y;
    b1Y=b3Y;
    b3Y=w;
    eY+=200;
  }else if(b3Y== 250 && eX<b3X+45 && eX&rt;b3X-45 && eY<275 && eY&rt;225){
    eY=b3Y;
    eX=b3X+25;
    w=b2Y;
    b2Y=b1Y;
    b1Y=b3Y;
    b3Y=w;
    eY+=200;
  }else if(eY==640){
    eY=640;
  }else if(eY==b1Y && eX<b1X-25 || eX&rt;b1X+25){ 
    for(int i=0;i<500;i++)eY--;
    image(over, 0, 0, 600, 700);
    /*for(int j=0;j<2;j++){
      if(score1&rt;0)score1-=1;
    }*/
  }else if(eY==b2Y && eX<b2X-25 || eX&rt;b2X+25){ 
    for(int i=0;i<500;i++)eY--;
    image(over, 0, 0, 600, 700);
    /*for(int j=0;j<2;j++){
      if(score1&rt;0)score1-=1;
    }*/
  }else if(eY==b3Y && eX<b3X-25 || eX&rt;b3X+25){ 
    for(int i=0;i<500;i++)eY--;
    image(over, 0, 0, 600, 700);
    /*for(int j=0;j<2;j++){
      if(score1&rt;0)score1-=1;
    }*/
  }
  
  //生命值(小雞)
  //image(life, 0, 30, 70, 50);
  //image(life, 80, 30, 70, 50);
  //image(life, 160, 30, 70, 50);
  //分數
  image(score, 350, 30, 100, 50);
  image(num[score1/1000], 455, 30, 30, 50);
  image(num[score1/100%10], 485, 30, 30, 50);
  image(num[score1/10%10], 515, 30, 30, 50);
  image(num[score1%10], 545, 30, 30, 50);
}
3, 圖片展示:



4, 影片展示:

5, 問題檢討和心得感想:
問題 ↓
最一開始碰到的問題是,要怎麼讓雞蛋往上拋,且有正常的動畫效果,後來的問題則是該如何使不同的籃子從不同的起始點開始移動,並且每個籃子都做不同的速度移動,好不容易都解決了,卻發現無法使籃子和雞蛋同時往下移以產生新的籃子,在這部分卡關了好久,最後終於想到解決辦法,但是雞蛋卻無法做動畫,很傷心 :(

改進 ↓
希望可以把雞蛋的動畫做好,然後關於計分的地方可以再作好一點,並且讓"生命值小雞"可以記錄,如此便能使每個玩家有三條命,不會一個不小心遊戲就結束了。
另外希望畫面可以在精緻豐富一些,例如在最一開始設計一個進入和可以選擇的介面,然後遊戲中的背景音樂能隨分數的增加而改變,也希望可以隨分數的增加來提高遊戲的難易度,最後希望結束畫面再漂亮一點~

心得 ↓
這個作業讓大家都好緊張,然後碰到困難就很慌亂,幸好有同學、學長姐和老師的幫助,才讓我們得以繼續下去,真的很感謝。
和小隊員一起完成一件作品的感覺好棒,過程中也好好玩,雖然目前沒有達到剛開始所設立的目標,但是我相信我們可以的 : D
然後發現任何事情真的都是要花時間和心力去完成,不可能有花少少時間就得到成效的事情。下次會再努力,並且提早時間開始準備!

謝謝大家:D