2015年6月29日 星期一

期末報告:體感跳舞機

(小提醒:聲音可以關小一點........)


我們的期末報告是體感跳舞機。
藉由右手的動作,來對應箭頭的上右下。
剛開始是先設定好遊戲的分數算法,以及設定三個箭頭。
之後設定鍵盤的WSD,代表著的分別是箭頭的上下右。
讓此遊戲可以用鍵盤玩。
最後,使用Faast,讓Pocessing跟Kinect做連結,
將鍵盤的WSD鍵用身體去做定義,
最後就完成了一個可以用身體來玩遊戲的體感跳舞機。



這是我們的程式碼:
//import de.voidplus.leapmotion.*; //import SimpleOpenNI.*; import ddf.minim.*; import SimpleOpenNI.*; SimpleOpenNI openni; //SimpleOpemNI context; PImage img, img1, img2, down, right, up; PImage img7; PImage img10; PImage img11; PImage img12; PImage img13; PImage img14; PImage img15; PImage img16; PImage img17; PImage img18; PImage img19; //LeapMotion leap; AudioPlayer player; Minim minim; int [] ran=new int[50]; float [] pointY=new float[50]; //int [] pointY=new int[50]; int h1, t1, t2, start, control, score, health, ground,time; float speed; int n1, n2, n3, n4, n5, nu1, nu2, nu3, nu4, nu5; void setup() { size(800, 600, P3D); for (int i=0; i<50; i++) { pointY[i]=-1; ran[i]=0; } img = loadImage("floor.jpg"); img1 = loadImage("tree.jpg"); img2 = loadImage("floor1.jpg"); down = loadImage("down.png"); right = loadImage("right.png"); up = loadImage("up.png"); img7 = loadImage("protect.png"); img10 = loadImage("0.png"); img11 = loadImage("1.png"); img12 = loadImage("2.png"); img13 = loadImage("3.png"); img14 = loadImage("4.png"); img15 = loadImage("5.png"); img16 = loadImage("6.png"); img17 = loadImage("7.png"); img18 = loadImage("8.png"); img19 = loadImage("9.png"); minim = new Minim(this); player = minim.loadFile("music.mp3", 2048); player.play(); t1=0; t2=0; control=0; start=0; score=0; health=5; h1=0; n1=0; n2=0; n3=0; n4=0; n5=0; nu1=10; nu2=100; nu3=1000; nu4=10000; nu5=100000; ground=0; time=1; speed=1.5; // leap = new LeapMotion(this).withGestures(); } void draw() { if (health==0)ground=1; if (ground==0)background(img); else background(img2); //image(img1, 0, 510, 800, 100); if (ground==0) { for (int i=1; i<=health; i++) { image(img7, 790-i*50, 10, 50, 50); } if (control>=1&&control<=4) { for (int i=0; i<50; i++) { if (control==1) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==1) { ran[i]=0; score+=speed*10; h1=1; } if (control==2) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==2) { ran[i]=0; score+=speed*10; h1=1; } if (control==3) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==3) { ran[i]=0; score+=speed*10; h1=1; } if (control==4) if (pointY[i]>=470&&pointY[i]<=570&&ran[i]==4) { ran[i]=0; score+=speed*10; h1=1; } } if (h1==0)health--; control=0; h1=0; } t1=0; for (int i=0; i<50; i++) if (pointY[i]<=100&&pointY[i]>=0)t1=1; if (t1==1)t2=1; else t2=0; if (t2==0) { ran[start]=int(random(1, 5)); pointY[start]=0; start++; } for (int i=0; i<50; i++) { if (ran[i]==1)image(down, 350, pointY[i], 80, 80); if (ran[i]==4)image(up, 350, pointY[i], 80, 80); if (ran[i]==3)image(right, 500, pointY[i], 80, 80); } for (int i=0; i<50; i++) if (ran[i]>=1&&ran[i]<=5)pointY[i]+=speed; } for(int i=0;i<50;i++) if(ran[i]>=1&&ran[i]<=3&&pointY[i]==600){ ran[i]=0; health--; } n1=score%nu1; n2=score%nu2/10; n3=score%nu3/100; n4=score%nu4/1000; n5=score%nu4/10000; if (n1==0)image(img10, 140, 10, 40, 40); if (n1==1)image(img11, 140, 10, 40, 40); if (n1==2)image(img12, 140, 10, 40, 40); if (n1==3)image(img13, 140, 10, 40, 40); if (n1==4)image(img14, 140, 10, 40, 40); if (n1==5)image(img15, 140, 10, 40, 40); if (n1==6)image(img16, 140, 10, 40, 40); if (n1==7)image(img17, 140, 10, 40, 40); if (n1==8)image(img18, 140, 10, 40, 40); if (n1==9)image(img19, 140, 10, 40, 40); if (n2==0)image(img10, 100, 10, 40, 40); if (n2==1)image(img11, 100, 10, 40, 40); if (n2==2)image(img12, 100, 10, 40, 40); if (n2==3)image(img13, 100, 10, 40, 40); if (n2==4)image(img14, 100, 10, 40, 40); if (n2==5)image(img15, 100, 10, 40, 40); if (n2==6)image(img16, 100, 10, 40, 40); if (n2==7)image(img17, 100, 10, 40, 40); if (n2==8)image(img18, 100, 10, 40, 40); if (n2==9)image(img19, 100, 10, 40, 40); if (n3==0)image(img10, 60, 10, 40, 40); if (n3==1)image(img11, 60, 10, 40, 40); if (n3==2)image(img12, 60, 10, 40, 40); if (n3==3)image(img13, 60, 10, 40, 40); if (n3==4)image(img14, 60, 10, 40, 40); if (n3==5)image(img15, 60, 10, 40, 40); if (n3==6)image(img16, 60, 10, 40, 40); if (n3==7)image(img17, 60, 10, 40, 40); if (n3==8)image(img18, 60, 10, 40, 40); if (n3==9)image(img19, 60, 10, 40, 40); if (n4==0)image(img10, 20, 10, 40, 40); if (n4==1)image(img11, 20, 10, 40, 40); if (n4==2)image(img12, 20, 10, 40, 40); if (n4==3)image(img13, 20, 10, 40, 40); if (n4==4)image(img14, 20, 10, 40, 40); if (n4==5)image(img15, 20, 10, 40, 40); if (n4==6)image(img16, 20, 10, 40, 40); if (n4==7)image(img17, 20, 10, 40, 40); if (n4==8)image(img18, 20, 10, 40, 40); if (n4==9)image(img19, 20, 10, 40, 40); if (n5==0)image(img10, 180, 10, 40, 40); if (n5==1)image(img11, 180, 10, 40, 40); if (n5==2)image(img12, 180, 10, 40, 40); if (n5==3)image(img13, 180, 10, 40, 40); if (n5==4)image(img14, 180, 10, 40, 40); if (n5==5)image(img15, 180, 10, 40, 40); if (n5==6)image(img16, 180, 10, 40, 40); if (n5==7)image(img17, 180, 10, 40, 40); if (n5==8)image(img18, 180, 10, 40, 40); if (n5==9)image(img19, 180, 10, 40, 40); println(speed); time++; if(time%500==0)speed+=0.5; } //490 560 void keyPressed() { if (key=='s') control=1; if (key=='d') control=3; if (key=='w') control=4; }








然後跟Faast做連結,
先設定好WSD的動作定義
W(上):右手需高於頭部15公分
S(下):右手需低於軀幹15公分
D(右):右手需比軀幹右30公分
之後,點上connect,和kinect做連結後,start Emulator
就能和Processing做連結了。









設定出自己的定義:











遊戲畫面:
在箭頭到達背景圖片沙灘部位時,做出相對應的動作。
最多能夠失敗五次,
每失敗一次,右上角的藍色球球就會少一顆。
左上角是計分,會依正確次數去做累計,
正確次數越多(累計),分數將以等差去遞增上去。


沒有留言:

張貼留言