2015年1月18日 星期日

期末作品




期末作品


太鼓達人


import ddf.minim.*; Minim minim; AudioPlayer mu0,mu1,mu2,mu3,mu4,mu5; import processing.serial.*; Serial myPort; PImage img,imgBG,drum,B,R,P; int time=450*4; int runX[] = new int[100]; int drumcolor[] = new int[100]; int score=0; int but; void setup() { myPort = new Serial(this, "COM3", 9600); size(1200,390); imgBG = loadImage("BG.png"); drum = loadImage("drum.png"); B = loadImage("B.png"); R = loadImage("R.png"); P = loadImage("P.png"); imgBG.resize(1200,390); imageMode(CENTER); runX[0]=1050; for(int i=1;i<100;i++) { runX[i] = runX[i-1] + int(random(100,400)); } for(int i=0;i<100;i++) { drumcolor[i] = int(random(1,3)); } minim = new Minim(this); mu0 = minim.loadFile("Do_Do_Do.mp3"); mu1 = minim.loadFile("hitclap.mp3"); mu2 = minim.loadFile("slidertick.mp3"); mu0.rewind(); mu0.play(); } void draw() { background(imgBG); time--; textSize(30); fill(0, 0, 0); text(time/60,80,120); textSize(20); fill(0, 0, 0); text("Time:",75,80); if (myPort.available()>0) { but = myPort.read(); } col(); button(); image(drum,102,288,205,205); textSize(40); fill(0, 0, 0); text("Score:",850,150); textSize(40); fill(0, 0, 0); text(score,980,150); if(time==0) { minim.stop(); background(0, 0, 0); textSize(30); fill(250, 150, 0); text("Time's up",470,100); text("Your score is",450,150); textSize(80); text(score, 445,250); noLoop(); } } void col() { for(int i=0;i<100;i++) { if(drumcolor[i]==1) { image(B,runX[i]-=5,276,130,130); } if(drumcolor[i]==2) { image(R,runX[i]-=5,276,130,130); } } } void button() { if(but =='B') { for(int i=0;i<100;i++) { if(drumcolor[i]==1) { if(runX[i]<310&&runX[i]>270) { image(P,runX[i]-=5,276,130,130); score+=50; mu1.rewind(); mu1.play(); } } } println("B"); } if(but=='R') { for(int i=0;i<100;i++) { if(drumcolor[i]==2) { if(runX[i]<310&&runX[i]>270) { image(P,runX[i],276,130,130); score+=50; mu2.rewind(); mu2.play(); } } } println("R"); } if(but=='N') { println("N"); } }








My teammate :-)





沒有留言:

張貼留言