我們這組做的是快打小蜜蜂
當你的手比五的時候,可以控制電蚊拍去砍殺蜜蜂
如果不是,電蚊拍就不會動
當遊戲結束時
左手握拳可以重新遊戲
http://youtu.be/RQu8M9rP2Sc
import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage bee,img,hit;
PVector pos[]=new PVector[10];
import ddf.minim.*;
Minim minim;
AudioPlayer startm,hitm;
float nowX=0,nowY=0,nowA=0;
float grabX=200, grabY=100;
int countDown=1,Score=0;
boolean start=true;
void setup(){
size(600,600,P3D);
minim = new Minim(this);
startm = minim.loadFile("startm.mp3");
hitm = minim.loadFile("hitm.mp3");
startm.play();
img = loadImage("d.jpg");
bee = loadImage("bee.png");
hit = loadImage("hit.gif");
imageMode(CENTER);
leap = new LeapMotion(this);
for(int i=0;i<10;i++)
{
pos[i]=new PVector(60*i,-random(600));
}
}
void draw(){
background(img);
nowY+=cos(nowA);nowX+=sin(nowA);
for(int i=-10;i<=10;i++)
{
for(int j=-50;j<=30;j++)
{
pushMatrix();
translate(300,400);
rotateX(radians(50));
rotateZ(nowA);
translate(i*20+nowX,j*20+nowY,0);
fill(0,255,255);box(200);
popMatrix();
}
}
for(int i=0;i<10;i++)
{
image(bee,pos[i].x,pos[i].y, width/10, height/10);
pos[i].y+=20;
if(pos[i].y>600) pos[i].y=-random(300);
if(dist(grabX,grabY,pos[i].x,pos[i].y)<100)
{
fill(255,0,0);
pos[i].y=-random(300);
if(start)
Score+=100;
hitm.rewind();
hitm.play();
}
else fill(255);
}
if(countDown==0)
{
start=false;
background(255,0,0);
text("GAME OVER",200,100);
text("please fist left hand to restart",75,200);
startm.close();
hitm.close();
}
fill(0,0,255);
textSize(32);
text("Time:"+countDown,20,50);
if(frameCount%60==0&&countDown>0)countDown--;
text("Score:"+Score,200,50);
for(Hand hand : leap.getHands())
{
int n=hand.getOutstrechtedFingers().size();
if(hand.isRight())
{
if(n==5)
{
grabX=hand.getPosition().x;
grabY=hand.getPosition().y;
}
}
if(hand.isLeft())
{
if(n==0)reset();
}
}
image(hit,grabX,grabY,width/5, height/5);
}
void keyPressed()
{
if (key==' ')reset();
}
void reset()
{
start=true;
startm = minim.loadFile("startm.mp3");
hitm = minim.loadFile("hitm.mp3");
startm.play();
hitm.play();
Score=0;
countDown=10;
}
沒有留言:
張貼留言