2014年10月27日 星期一

期中作品~~~

遊戲截圖↓↓↓
-----------------------------------------------------------------------------------

遊戲實測錄影↓↓↓
---------------------------------------------------------------------------------------

=========================期中作業程式碼 玩法和缺點↓↓↓======================
成員:00160104 張偉涵 01160306 呂季樺
遊戲介紹及玩法:
這是一款操作大砲打天上飛機的遊戲,透過鍵盤的左右鍵來操作大砲的位置,藉此閃躲飛機丟下來的炸彈,然後透過Ctrl鍵來發射大砲打飛機,打死飛機會得到分數,但是被飛機的炸彈打中就會遊戲結束。
不過,在子彈的碰撞上位置並沒能抓的相當精確,會有些許誤差,有待改善。
還有飛機被大砲打中後不會消失...
程式碼:
PImage plane[]=new PImage[3],imgBG,canon,bullet;
int pX[]={0,0,0},pY[]={0,0,0},cX[]={375},cY[]={500},bX[]={387},bY[]={520};
float pVX[]={1,1,1},pVY[]={1,1,1},bVY=2,bLife[]={0},pbX[]={0,0,0},pbY[]={0,0,0},pbv=1;
int shoot=0,gameover=0,score=0;
void setup(){
  size(800,600);
  imgBG=loadImage("sky.png");
  canon=loadImage("canon.png");
  bullet=loadImage("bullet.png");
  for(int i=0;i<3;i++)  plane[i]=loadImage("plane"+int(random(3))+".png");
  for(int i=0;i<3;i++){//plane and planeBullet begin
    pX[i]=int(random(30))*25;
    pbX[i]=pX[i]+30;
    pY[i]=int(random(7))*25+25;
    pbY[i]=pY[i]+31;
  }
}
void draw(){
  background(255);
  image(imgBG,0,50);
  image(bullet,bX[0],bY[0],40,40);
  image(canon,cX[0],cY[0],80,100);
  if(gameover>0){//Gameover
    fill(255,0,0);
    rect(0,0,800,600);
    textSize(100);
    fill(0);
    text("GameOver!", 125, 200);
    textSize(80);
    text("Score = "+score, 125,300 );
  }
  else{
    fill(0);
    textSize(18);
    text("use <- and -> to control canon location, click Ctrl to shoot.", 5, 20);
    for(int i=0;i<3;i++){
      if(abs(pX[i]-bX[0])<=100 &&abs(pY[i]-bY[0])<5){
        score+=1;
        //image(plane[i],pX[i],pY[i],100,60,1);
      }
    }
    text("Score = "+score, 5, 40);
    for(int i=0;i<3;i++){
      if(abs(pbX[i]-cX[0])<=10 &&pbY[i]>487 ) gameover++;
    }
    for(int i=0;i<3;i++){//draw plane and planeBullet
      fill(0);
      ellipse(pbX[i],pbY[i],10,10);
      image(plane[i],pX[i],pY[i],100,60);
    }
    for(int i=0;i<3;i++){//plane speed and pBspeed
       if(pX[i]>700){
         pX[i]=0;
         pbX[i]=30;
         plane[i]=loadImage("plane"+int(random(3))+".png");
         pY[i]=int(random(7))*25+25;
         pVX[i]=1;
       }
     
       else if(pbY[i]>600){
         pbY[i]=pY[i]+31;
         pbv=1;
       }
       else{
         pX[i]+=pVX[i];
         pbX[i]+=pVX[i]-0.02;
         pVX[i]+=0.05;
         pbY[i]+=pbv;
         pbv+=0.05;
      }
    }
    if(shoot>0){
      //image(bullet,bX[0],bY[0],40,40);
       for(int j=0;j<1;j++){//canonBullet speed
           if(bY[j]<30){
             bX[j]=cX[0]+20;
             bY[j]=500;
             bVY=2;
             shoot=0;
           }
           else{
             bY[j]-=bVY;
             bVY+=0.5;
           }
      }
      }
  }
}
void keyPressed(){
   if(keyCode==RIGHT && cX[0]<725 && bY[0]<500) cX[0]+=50;
   else if(keyCode==RIGHT && cX[0]<725 ){
     cX[0]+=50;
     bX[0]+=50;
   }
   if(keyCode==LEFT && cX[0]>0&& bY[0]<500) cX[0]-=50;
   else if(keyCode==LEFT && cX[0]>0){
     cX[0]-=50;
     bX[0]-=50;
   }
   if(keyCode==CONTROL) shoot++;
}

沒有留言:

張貼留言