2016年4月14日 星期四

week08

組員 陳曉彤 陳薇亘

期中主題

疊疊樂

由於第一學期沒有修導論
所以我們在這堂課特別辛苦

但有很多人的幫助
我們完成這個作業了
但這個遊戲有時候還是有點遲緩

程式碼
import de.voidplus.leapmotion.*; LeapMotion leap; PVector myFinger1 = new PVector(); PVector myHand = new PVector(); float dis=0; PVector []pos = new PVector[1000]; int now = 1; int frame=1; boolean bStartDown=false, bStartNext=false, bGameOver=false; float down =0 ; void setup() { size(600, 400, P3D); for (int i=0; i<1000; i++)pos[i]=new PVector(0, 50-i*50, 0); leap = new LeapMotion(this); } void draw() { int fps = leap.getFrameRate(); for (Hand hand : leap.getHands ()) { myHand=hand.getPosition(); for (Finger finger : hand.getFingers ()) { switch(finger.getType()) { case 0: // System.out.println("thumb"); break; case 1: myFinger1 = finger.getPosition(); // System.out.println("index"); break; case 2: // System.out.println("middle"); break; case 3: // System.out.println("ring"); break; case 4: // System.out.println("pinky"); break; } } dis=dist(myHand.x, myHand.y, myFinger1.x, myFinger1.y); println(dis); } if (bGameOver)background(255, 0, 0, 100); else background(0,0,0); translate(width/2, height/2); translate(0, down); for (int i=0; i<=now; i++) { pushMatrix(); translate(pos[i].x, pos[i].y); box(50, 50, 50); popMatrix(); } if (bStartNext) { for (int i=0; i<=now; i++) { pos[i].y+=50; } bStartNext=false; } if (bStartDown) { pos[now-1].y+=2; if(pos[now-1].y>0){ bStartNext=true; bStartDown=false; } } // if (dis>60/*pos[now].y>0 */&& frame%60==1) { bStartDown=true; now++; if (abs(pos[now].x-pos[now-1].x)>50)bGameOver=true; } else { pos[now].x=myFinger1.x-width/2; pos[now].y=myFinger1.y-height/2; println(pos[now].x + " " +pos[now].y); } if(bGameOver!=true) { textSize(32); text("Score:" + now,100,100); } else {background(255, 0, 0, 100); fill(0,0,0); textSize(50); text("g a m e o v e r",-200,0);} frame++; } void mousePressed() { bStartDown=true; }



沒有留言:

張貼留言