Minim minim;
AudioPlayer player;
PImage imgbackground;
import de.voidplus.leapmotion.*;
LeapMotion leap;
int []drumColor = new int [93];
int []drumX = new int[93];
int score =0;
int x=600;
PImage img5;
void setup() {
size(600,400);
imgbackground = loadImage("background.png");
img5=loadImage("img5.png");
imageMode(CENTER);
leap = new LeapMotion(this);
for (int i=0;i<93;i++) {
drumColor[i]=int(random(2));
drumX[i]=600+i*100;
}
}
void draw() {
float hand_x=0;
float hand_y=0;
background(imgbackground);
fill(255);
ellipse(135, 137.5, 38, 38);
int fps = leap.getFrameRate();
for(Hand hand : leap.getHands()){
hand.draw();
PVector hand_position = hand.getPosition();
image(img5, hand_position.x, hand_position.y+40);
hand_x=hand_position.x;
hand_y=hand_position.y;
}
for (int i=0;i<93;i++) {
if (drumX[i]-135<3 && drumX[i]-135>-3) {
if (hand_x>0 && hand_x<400 && drumColor[i]==0) {
score++;
println("分數:"+score);
}
else if (hand_x>400 && hand_x<800 && drumColor[i]==1) {
score++;
println("分數:"+score);
}
fill(0, 255, 0);
ellipse(drumX[i], 137.5, 36, 36);
drumX[i]-=2;
}
else if (drumColor[i]==0) {
fill(255, 0, 0);
ellipse(drumX[i], 137.5, 36, 36);
drumX[i]-=2;
}
else if (drumColor[i]==1) {
fill(0, 0, 255);
ellipse(drumX[i], 137.5, 36, 36);
drumX[i]-=2;
}
}
fill(0);
textFont(createFont("calibri",40));
textSize(30);
text("score : "+score, 230, 300);
}

沒有留言:
張貼留言