2016年6月15日 星期三

期末作業demo啦!

https://youtu.be/tFO2NFEXaLQ







import ddf.minim.*; Minim minim; AudioPlayer start, yisell; import SimpleOpenNI.*; SimpleOpenNI openni; PVector []pos=new PVector[17]; PVector rect; int count=600, count2=600, count3=600; int blood=10, blood2=10, blood3=10; int k=0, t=0; PImage imgBG, imgBG2, imgBG3,imgBG4,imgBGF, img2, img3, img4; void setup() { size(800, 600); minim=new Minim(this); start=minim.loadFile("BellStartRound.mp3"); yisell=minim.loadFile("ccheer.wav"); openni=new SimpleOpenNI(this); openni.enableRGB(); openni.enableDepth(); openni.enableUser(); rect=new PVector(width/2, height/2); for (int i=0; i<17; i++) { pos[i]=new PVector(0, 0, 0); } //img=loadImage("7.jpg"); img2=loadImage("1.png"); img3=loadImage("2.png"); img4=loadImage("3.png"); imgBGF=loadImage("first.jpg"); imgBG=loadImage("s1.jpg"); imgBG2=loadImage("s2.jpg"); imgBG3=loadImage("s3.jpg"); imgBG4=loadImage("win.jpg"); yisell.play(); yisell.loop(); } boolean bTouched=false; void draw() { // ==1 openni.update(); image(imgBGF, -30, 0, 900, 900); image(openni.userImage(), 0, 0, 32*4, 24*4); if (bTouched) fill(255, 0, 0); rect(300, 230, 300, 100); fill(0); textSize(50); text("PLAY", 400, 300); fill(200); //yisell.pause(); ///////////////scene1 // if (count>=0) //if (count==600) //blood=10; //background(255); if (dist(pos[6].x, pos[6].y, rect. x, rect.y)<100&&dist(pos[7].x, pos[7].y, rect.x, rect.y)<80) bTouched=true; if (bTouched==true) { //start.rewind(); start.play(); println("sssss"); image(imgBG, -30, 0, 900, 900); image(img2, 500, 200, 300, 300); image(openni.userImage(), 0, 0, 32*4, 24*4); textSize(50); text("Time: "+int(count/60), 200, 100);//time count--; text("Blood: "+int(blood), 500, 100); //rect(500, 200, 100, 500);//rect(x,y,width,height) fill(200); if (count<=0&&blood>0) { image(imgBG, -30, 0, 900, 900); textSize(50); text("You Are A Loser!!!", 400, 300); fill(233); yisell.pause(); } ///////////////////level2 if ((count<=0&&blood<=0)||(count>=0&&blood<=0)) { if (count2>=0) { if (count2==600) { start.play(); blood2=20; // yisell.play(); // yisell.loop(); } image(imgBG2, -30, 0, 900, 900); textSize(50); fill(0); text("Time: "+int(count2/60), 200, 100);//time count2--; text("Blood: "+int(blood2), 500, 100); image(img3, 500, 200, 400, 300); image(openni.userImage(), 0, 0, 32*4, 24*4); } } if (count2<0&&blood2>0) { image(imgBG2, -30, 0, 900, 900); textSize(50); text("You Are a Loser!!!", 400, 300); fill(233); yisell.pause(); } ///////////////////level3 if ((count2<=0&&blood2<=0)||(count2>=0&&blood2<=0)) { if (count3>=0) { if (count3==600) { start.play(); blood3=30; //yisell.play(); // yisell.loop(); } image(imgBG3, -30, 0, 900, 900); textSize(50); fill(255); text("Time: "+int(count3/60), 200, 100);//time count3--; text("Blood: "+int(blood3), 500, 100); image(img4, 500, 200, 400, 300); image(openni.userImage(), 0, 0, 32*4, 24*4); } } if (count3<=0&&blood3>0) { image(imgBG3, -30, 0, 900, 900); textSize(50); text("You Are a Loser!!!", 400, 300); fill(233); yisell.pause(); } if ((count3<=0&&blood3<=0)||(count3>=0&&blood3<=0)) { if (count3>=0) { if (count3==600) { blood3=10; start.play(); } image(imgBG4, -30, 0, 900, 900); textSize(50); fill(255); } } } int []userList=openni.getUsers(); for (int userId : userList) { for (int i=0; i<16; i++) { openni.getJointPositionSkeleton(userId, i, pos[i]); openni.convertRealWorldToProjective(pos[i], pos[i]); if (now==i) fill(255, 0, 0); //image(img2,0,1,30,30); else fill(255); //ellipse(pos[i].x,pos[i].y,30,30); } myLine(0, 1); myLine(1, 2); myLine(1, 3); myLine(2, 4); myLine(3, 5);//left hands myLine(4, 6);//r myLine(5, 7);//right hands myLine(1, 8);//body myLine(8, 9); myLine(8, 10);//right big leg myLine(9, 11);//left big leg myLine(10, 12); myLine(11, 13);//left leg myLine(12, 14); myLine(13, 15);//right leg fill(255); ellipse(pos[0].x, pos[0].y, 100, 100); println(userId); } /*if(userId==1) for(int i;i<16;i++)hit=dis(i);*/ dis(); println(blood); } void dis() { // println("k:"+k); if (dist(pos[6].x, pos[6].y, rect.x+100, rect.y+5)<80) { k++; if (k%10==0) { blood--; blood2--; blood3--; //yisell.play(); //yisell.loop(); } } if (dist(pos[7].x, pos[7].y, rect.x+150, rect.y+5)<80) { k++; if (k%10==0) { blood--; blood2--; blood3--; //yisell.play(); // yisell.loop(); } } } void myLine(int a, int b) { strokeWeight(20); line(pos[a].x, pos[a].y, pos[b].x, pos[b].y); } int now=0; void keyPressed() { now++; if (now>=16)now=0; println(now); } void onNewUser(SimpleOpenNI curContext, int userId) { curContext.startTrackingSkeleton(userId); }

沒有留言:

張貼留言