2014年4月28日 星期一

第九週作業 鄭羽婷

完成三個畫面白蘿菠!!接上leap mation





import de.voidplus.leapmotion.*;
LeapMotion leap;
import ddf.minim.*;
Minim minim;
AudioPlayer star;
PImage BKimg, F3img, F32img, F2img, F1img;//background
PImage blood, M1, M0, M2;//blood,mandora
PImage finimg, finimg2, agaimg, startimg;
int M[]=new int [11];
int n;
boolean Ran=false;
boolean pull[]=new boolean[11];
int Y;
boolean st1=true, st2=false, st3=false;
int Music=1;
int siteX[]= {
60, 146, 235, 16, 103, 193, 281, -10, 90, 190, 290
};
int siteY[]= {
258, 328, 410
};
int ButX[]= {
115, 197, 288, 70, 155, 246, 335, 55, 155, 250, 350
};
int ButY[]= {
282, 360, 435
};
int siteY2[]= {
258, 258, 258, 328, 328, 328, 328, 410, 410, 410, 410
};
int FingerX, FingerY;
int Y2;//3
boolean stage3=true;
int num[]=new int [500];
int FX[]=new int [500];
int FY[]=new int[500];
int FB[]=new int[500];
int FBY[]=new int[500];
int Total;
int sum=0;
int time2;
int ToI=0;
boolean count=true;//3
int time=0;
int MT[]=new int[11];
int first[]=new int[11];
boolean puM[]=new boolean [11];
int BloodT=225;//225
void setup() {
leap = new LeapMotion(this);
minim = new Minim(this);
star = minim.loadFile("a.mp3");
size(400, 700);
finimg = loadImage("stage3.png");
finimg2 = loadImage("stage32.png");
agaimg= loadImage("again.png");
startimg= loadImage("stage1.JPG");
BKimg = loadImage("fload.png");
F3img = loadImage("F3.jpg");
F32img = loadImage("F32.jpg");
F2img = loadImage("F2.jpg");
F1img = loadImage("F1.jpg");
blood = loadImage("blood.png");
M1 = loadImage("A.png");
M0 = loadImage("baby.png");
M2 = loadImage("bad.png");
for (int i=0;i<11;i++) {
pull[i]=false;
puM[i]=false;
}
for (int i=0;i<500;i++) {
FX[i]=150;
FY[i]=500;
FB[i]=(int)random(-6, 6);
FBY[i]=(int)random(3, 6);
}
}
void draw() {
background(204);
if (leap==null)return;
for (Hand hand : leap.getHands()) {
// FINGERS
for (Finger finger : hand.getFingers()) {
FingerX=(int)finger.getPosition().x;
FingerY=(int)finger.getPosition().y;
}
}
if (st1)STAGE1();
if (st2)STAGE2();
if (st3)STAGE3();
for (Hand hand : leap.getHands()) {
// FINGERS
for (Finger finger : hand.getFingers()) {
finger.draw();
}
}
}
void music() {
star.loop();
}
void STAGE1() {
if (Music==1) {
star.close();
star=minim.loadFile("a.mp3");
music();
}
Music=2;
image(startimg, 0, 0);
if (FingerX>=265&&FingerX<=355&&FingerY>=575&&FingerY<=610) {
st1=false;
st2=true;
}
}
void STAGE2() {
if (Music==2) {
star.close();
star=minim.loadFile("b.mp3");
music();
}
Music=3;
image(BKimg, 0, 0);
if (BloodT==0) {
st3=true;
st2=false;
}
ranMandow();
pullMandora(0, 2, 0);
image(F1img, 0, 300);
pullMandora(3, 6, 1);
image(F2img, 0, 370);
image(F32img, 0, 412);
pullMandora(7, 10, 2);
image(F3img, 0, 450);
fill(‪#‎2EB207‬);
rect(150, 570, 230, 50, 7);
fill(‪#‎F7801E‬);
rect(150, 575, BloodT, 40, 7);
image(blood, 5, 520, 150, 150);
if (time%10==0)BloodT--;
}
void STAGE3() {
if (Music==3) {
star.close();
star=minim.loadFile("c.mp3");
music();
}
Music=1;
if (stage3)image(finimg, 0, 0);
else {
image(finimg2, 0, 0);
textSize(60);
fill(‪#‎833D14‬);
text(sum, 170, 340);
if (time2%10==0&&Total!=ToI)ToI++;
for (int i=Total-1;i>=Total-ToI;i--) {
if (time2%10==0&&i==Total-ToI) {
if (count) {
switch(num[i]) {
case 0:
sum-=2;
break;
case 1:
sum+=5;
break;
default:
sum-=3;
}
}
}
else switch(num[i]) {
case 0:
image(M0, FX[i], FY[i], 100, 100);
break;
case 1:
image(M1, FX[i], FY[i], 130, 120);
break;
default:
image(M2, FX[i], FY[i], 120, 120);
}
FX[i]-=FB[i];
FY[i]-=FBY[i];
}
if (Total-ToI==0) {
count=false;
textSize(50);
fill(‪#‎FF0000‬);
if (sum<50)text("HA!H!H!", 130, 300);
else if (sum<10) text("OK!K!K!", 130, 300);
else if (sum<150)text("GOOD!G!G!", 130, 300);
}
}
if (Total==ToI) {
if (FY[Total-1]<=0)image(agaimg, 150, 350, 100, 150);
println(Total);
if (FingerX>=150&&FingerX<=250&&FingerY>=350&&FingerY<=500) {
st1=true;
st3=false;
sum=0;
ToI=0;
Ran=false;
stage3=true;
count=true;
time=0;
BloodT=225;
}
}
time2++;
if (FingerX>=140&&FingerX<=270&&FingerY>=490&&FingerY<=565) {
if ((Y2-FingerY)>5) {
stage3=false;
}
}
Y2=FingerY;
}
void ranMandow() {
n=(int)random(0, 11);
if (time%50==0) {
for (int i=0;i<=10;i++)if (M[i]==0)Ran=true;
while (Ran) {
n=(int)random(0, 11);
if (M[n]!=0)continue;
else {
Ran=false;
M[n]=1;
}
}
}
time++;
}
void pullMandora(int I1, int I2, int YS) {
for (int i=I1;i<=I2;i++) {
if (M[i]==1) {
if (puM[i]==false) {
if (FingerX<=ButX[i]+20&&FingerX>=ButX[i]-20&&FingerY<=ButY[YS]+20&&FingerY>=ButY[YS]-20) {
pull[i]=true;
if (first[i]==0)Y=FingerY;
first[i]++;
}
else pull[i]=false;
if (pull[i]) {
if ((Y-FingerY)>=5) {
if (MT[i]<100) num[Total]=0;
else if (MT[i]<200) num[Total]=1;
else if (MT[i]<300) num[Total]=2;
puM[i]=true;
Total++;
}
if (MT[i]<100)image(M0, siteX[i], siteY[YS], 100, 100);
else if (MT[i]<200)image(M1, siteX[i], siteY[YS]-10, 120, 100);
else if (MT[i]<300)image(M2, siteX[i], siteY[YS], 100, 100);
Y=FingerY;
}//become big
else {
MT[i]++;
first[i]=0;
if (MT[i]<100) image(M0, siteX[i], siteY[YS]+10, 100, 90);
else if (MT[i]<200)image(M1, siteX[i], siteY[YS], 120, 100);
else if (MT[i]<300)image(M2, siteX[i], siteY[YS]+10, 100, 100);
else {
M[i]=0;
MT[i]=0;
}
}
}//puM=false
else {
if (MT[i]<100)image(M0, siteX[i], (siteY2[i]-=10), 100, 100);
else if (MT[i]<200) image(M1, siteX[i], (siteY2[i]-=10)-10, 130, 120);
else if (MT[i]<300) image(M2, siteX[i], (siteY2[i]-=10), 120, 120);
if (siteY2[i]<0) {
puM[i]=false;
M[i]=0;
MT[i]=0;
siteY2[i]=siteY[YS];
}
}//puM=true
}
}
}

沒有留言:

張貼留言