2016年12月15日 星期四

Week8 錡洛誼上課筆記

接金幣遊戲
import de.voidplus.leapmotion.*;  
LeapMotion leap;
void setup(){
  size(800,500,P3D);                   
  leap=new LeapMotion(this);
}
float coinX=240, coinY=0, coinVX=0, coinVY=3;    
int score=0;                                               
void draw(){
  background(255);                                 
  coinY += coinVY;                                   
  fill(255,0,0); ellipse(coinX, coinY, 60,60);
  if(coinY>480) {
  coinY=0;
  coinX=random(640);
  }
  for(Hand hand : leap.getHands()){          
   //hand.draw();
   PVector pos = hand.getPosition();
   //println(pos);
   fill(255,0,0); ellipse(pos.x, pos.y, 100,100);
   if(dist(pos.x, pos.y, coinX, coinY)<100){
     score += 10;                                             
     coinY=0;
     coinX=random(640);
   }
  }
  fill(0,255,0);
  textSize(40);
  text("Score:" + score, 500,100);
}

沒有留言:

張貼留言