2016年4月5日 星期二

week06期中作品進度!!!!!

我們的打排球遊戲是限時!

時間限制內得分越多,就是獲勝!!


import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pika,pika1,ball,ballv,box,leftPos;
int count=1860;
void setup(){
  size(600,400,P3D);
  leap=new LeapMotion(this);
  pika=new PVector(width/4,height/1.17,0);
  pika1=new PVector(width/1.35,height/1.17,0);
  ball=new PVector(100,100,0);
  ballv=new PVector(2,2,0);
  box=new PVector(width/2,height/1.2,0);
  noStroke();
}
void draw(){
 
  lights();
  if(count<60)
  background(255);
   else{
    background(155);
    count--;
  }
  textSize(50);
  text("Time: "+int(count/60),100,100);
  for(Hand hand:leap.getHands()){
    PVector pos = hand.getPosition();
    pika.x=pos.x; pika.y=pos.y;
    pika1.x=pos.x; pika1.y=pos.y;
   
    if(hand.isLeft() ){
      pushMatrix();
       translate(pika1.x, pika1.y);
       fill(#FAE600);
       sphere(50);
         pushMatrix();
           ball.x += ballv.x; ball.y+=ballv.y;
           if( dist(ball.x,ball.y,pika1.x,pika1.y)<50){
           float x=ball.x-pika1.x,y=ball.y-pika1.y, value=sqrt(x*x+y*y);
           ballv.x=2*x/value;
           ballv.y=2*y/value;
           }
          popMatrix();
        popMatrix();
      leftPos=pos;
    }else if(hand.isRight()){
       pushMatrix();
         translate(pika.x, pika.y);
         fill(#EA1A1A);
         sphere(50);
        popMatrix();
       
        pushMatrix();
          translate(ball.x,ball.y);
          fill(#FDFFBF);
          sphere(30);
           ball.x += ballv.x; ball.y+=ballv.y;
           if( dist(ball.x,ball.y,pika.x,pika.y)<50){
           float x=ball.x-pika.x,y=ball.y-pika.y, value=sqrt(x*x+y*y);
           ballv.x=2*x/value;
           ballv.y=2*y/value;
         }
         if(ball.x > width-50|| ball.x<50) ballv.x=-ballv.x;
         if(ball.y > height-50|| ball.y<50) ballv.y=-ballv.y;
        popMatrix();
      }
  }
 
  pushMatrix();
  translate(box.x,box.y);
  fill(255,255,255);
  box(30,350,100);
  ball.x += ballv.x; ball.y+=ballv.y;
   if(ball.x>=box.x-15&&ball.x<=box.x+10&&ball.y>=box.y-200&&ball.y<=box.y+200){
     float x=ball.x-box.x,y=ball.y-box.y, value=sqrt(x*x+y*y);
     ballv.x=2*x/value;
     ballv.y=2*y/value;
  }//ball,box
  popMatrix();
 
  pushMatrix();
  ball.x += ballv.x; ball.y+=ballv.y;
   if(ball.x==400&&ball.y==600){
     float x=ball.x-box.x,y=ball.y-box.y, value=sqrt(x*x+y*y);
     ballv.x=2*x/value;
     ballv.y=2*y/value;
  }//ball,floor
  popMatrix();
}


沒有留言:

張貼留言