Demo影片 :
Code:
import ddf.minim.*;
import processing.serial.*;
AudioPlayer player,SE;
Minim minim;
Serial myPort;
int val;
int angle;
PImage img1,img2,img3,bg,win,copyright,copyright2;;
PImage imgMan,leftwalk,rightwalk;
PImage imgface,imgface2,imgface3,symbol;
int Alpha=255,Alpha2=255;
float z2=int(random(150)+50);
float z3=int(random(150)+80);
float z4=int(random(150)+100);
float ac=0.03;
int BuildingX,BuildingX2,BuildingX3;
int stage=4;
int N=6;
int []thingType = new int [6] ;
float []thingX = new float [6];
int BGX=0;
float Reac,Rez2,Rez3,Rez4;
boolean sw=false;
boolean left=false,right=false,start=true;
int a=3;
int Time=800;
float GameTime=0;
int Score=0;
int move=0;
int blood=100;
//stage1 run
//stage2 gameover
//stage3 win
//stage4 menu
void setup(){
size(600,600);
String [] all = Serial.list();
String portName = all[all.length-1];
myPort = new Serial(this, portName, 9600);
img1=loadImage("monster1.png");
img2=loadImage("monster2.png");
img3=loadImage("monster3.png");
imgface=loadImage("image1.png");
imgface2=loadImage("image.png");
imgface3=loadImage("image3.png");
symbol = loadImage("symbol.png");
imgMan=loadImage("start.png");
leftwalk=loadImage("leftwalk.png");
rightwalk=loadImage("rightwalk.png");
bg=loadImage("bg.jpg");
win=loadImage("");
copyright = loadImage("copyright.bmp");
copyright2 = loadImage("copyright2.bmp");
imageMode(CENTER);
for ( int i = 0 ; i < N ; i++)
{
newThing(i);
}
minim = new Minim(this);
player = minim.loadFile("ST1.mp3");
SE = minim.loadFile("ken.mp3");
}
float newH;
float newH2;
float newH3;
float newH4=50;
int b;
void draw(){
if ( myPort.available() > 0)
{
val = myPort.read(); //Arduino Control
//angle = myPort.read();
println("val "+val);
println("ac "+ac);
// println("angle "+angle);
}
if (stage==3)
{
if (val==180) stage=4;
}
if (stage==4)
{
if (val==180) stage=1;
}
if (stage==1)
{
if (val==181)
{
if (sw==false)
{
z2-=ac;
ac+=0.001;
if (ac>0.88) ac=0.88;
}
}
/* if (val==179)
{
if (sw==false)
{
textSize(32);
fill(255,128,0);
text("PAUSE",250,300);
Reac = ac;
Rez2 = z2;
Rez3 = z3;
Rez4 = z4;
z2+=ac;
ac=0;
sw = true;
}
}
if (sw ==true)
{
if (val==181)
{
sw = false;
ac = Reac;
z2 = Rez2;
z3 = Rez3;
z4 = Rez4;
}
}*/
else z2-=ac;
if (val>79 && val<180)
{
if (sw==false)
{
if (val%79<10){thingX[0]-=val%79; thingX[1]-=val%79; thingX[2]-=val%79;thingX[3]-=val%79;thingX[4]-=val%79; thingX[5]-=val%79;}
if (val%79>10){thingX[0]-=10; thingX[1]-=10; thingX[2]-=10;thingX[3]-=10; thingX[4]-=10; thingX[5]-=10;}
right=true;
left=false;
start=false;
}
}
if (val>0 && val<79)
{
if (sw==false)
{
if (val%79<10) {thingX[0]+=val%79; thingX[1]+=val%79; thingX[2]+=val%79;thingX[3]+=val%79; thingX[4]+=val%79; thingX[5]+=val%79;}
if (val%79>10){ thingX[0]+=10; thingX[1]+=10; thingX[2]+=10;thingX[3]+=10; thingX[4]+=10; thingX[5]+=10;}
left=true;
right=false;
start=false;
}
}
}
if (stage==1&&sw==false)//stage01 runnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
{
if (a==1)
{
player.close();
player=minim.loadFile("ST1.mp3");
player.setGain(-20);
player.play();
player();
ac=0.03;
z2=int(random(150)+50);
z3=int(random(150)+80);
z4=int(random(150)+100);
blood=100;
Time=1000;
GameTime=0;
Score=0;
newH= 1360*atan(10/z2)/PI;
newH2= 1360*atan(10/z3)/PI;
newH3= 1360*atan(10/z4)/PI;
}
a=2;
GameTime+=0.5;
background(255);
image(bg,300,300,600,600);
fill(255,0,0);
rect(100,500,blood+GameTime*0.05-Score*20,50);
fill(255);
textSize(15);
text("HP "+(int)(blood+GameTime*0.05-Score*20),100,580);
text("GameTime"+GameTime,400,580);
fill(255,255,0);
textSize(15);
text("Press S To PAUSE",100,100);
text("Press R To Continue",100,150);
text("Press A To Access",400,100);
text("Press X or x To Move",400,150);
if ((blood+GameTime*0.05-Score*20)<0) stage=2;
//if (GameTime>3000) stage=3;
for ( int i = 0 ; i < N ; i++)
{
if (thingType[i]%6==1)
{
draw1(i);
if (z2<5&&(newH4-newH)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
if (thingType[i]%6==2)
{
draw2(i);
if (z3<5&&(newH4-newH2)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
if (thingType[i]%6==3)
{
draw3(i);
if (z4<5&&(newH4-newH3)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
drawMan();
newH= 1360*atan(10/z2)/PI;
newH2= 1360*atan(10/z3)/PI;
newH3= 1360*atan(10/z4)/PI;
if(z2<5||thingX[i]<0 ||thingX[i]>600)
{
z2=int(random(150)+50);
newH= 1360*atan(10/z2)/PI;
newThing(i);
}
if(z3<5||thingX[i]<0 ||thingX[i]>600)
{
z3=int(random(150)+80);
newH2= 1360*atan(10/z3)/PI;
newThing(i);
}
else if(z4<5||thingX[i]<0||thingX[i]>600)
{
z4=int(random(150)+100);
newH3= 1360*atan(10/z4)/PI;
newThing(i);
}
}
z2-=ac;
z3-=ac;
z4-=ac;
if (GameTime>1000){ stage=3;a=4;}
}
if (stage==2)//stage02 game overrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
{
if(a==2)
{
player.close();
player=minim.loadFile("ending.mp3");
player.setGain(-20);
player();
}
a=3;
background(255,0,0);
fill(0);
textSize(32);
text("Game Over", 200, 300);
text("ReStart Time :"+Time,200,400);
Time--;
line(230,150,215,180);
line(215,180,230,210);
line(230,210,400,210);
line(400,210,400,150);
line(400,150,230,150);
if (Time<800 && Time>600)
{
image(imgface,200,200,50,50);
textSize(16);
text("outch!",250,180);
}
if (Time<600 && Time>300)
{
image(imgface2,200,200,50,50);
textSize(16);
text("It's Really Hurt..",250,180);
}
if (Time<300)
{
image(imgface3,200,200,50,50);
textSize(16);
text("I Can Do Again!",250,180);
}
if (Time<0) stage=4;
}
if (stage==3) //stage03 winnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
{
if(a==4)
{
player.close();
player=minim.loadFile("win.mp3");
player.setGain(-10);
player();
}
background(0);
fill(255);
textSize(32);
text("You Make It! ", 200, 100);
text("Thanks For Your Playing!",100,200);
text(" This Game Design by↓",100,300);
text("&",285,360);
image(copyright,250,350,39,33);
image(copyright2,350,350,39,33);
text("Press W To ReStart Game",110,500);
a=3;
}
if (stage==4) //stage04 menuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
{
background(0);
if(a==3)
{
player.close();
player=minim.loadFile("start.mp3");
player.setGain(-10);
player();
}
textSize(16);
fill(255,0,0,Alpha);
text("run for life",250,80);
textSize(64);
stroke(50);
text("Monster Run",100,120);
if (Alpha>0) Alpha--;
if (Alpha==0) Alpha=255;
fill(255);
textSize(16);
text("Do Your Best To Avoid Monster",180,200);
text("Press Q To Start Game",200,300);
textSize(8);
text("TW",95,545);
text("Monster Run @2013 From Software",50,550);
image(symbol,300,450,200,200);
text("Tang Fan Gaming House @2013",430,550);
a=1;
}
}
void keyPressed()
{
if (stage==3)
{
if (key=='w' ||key=='W') stage=4;
}
if (stage==4)
{
if (key=='q' ||key=='Q') stage=1;
}
if (stage==1)
{
if (key=='a'||key=='A')
{
if (sw==false)
{
z2-=ac;
ac+=0.01;
if (ac>0.88) ac=0.88;
}
}
if (key=='s' ||key=='S')
{
if (sw==false)
{
textSize(32);
fill(255,128,0);
text("PAUSE",250,300);
Reac = ac;
Rez2 = z2;
Rez3 = z3;
Rez4 = z4;
z2+=ac;
ac=0;
sw = true;
}
}
if (key=='r' || key=='R')
{
if (sw ==true)
{
sw = false;
ac = Reac;
z2 = Rez2;
z3 = Rez3;
z4 = Rez4;
}
}
else z2-=ac;
if (key=='x')
{
if (sw==false)
{
thingX[0]-=20; thingX[1]-=20; thingX[2]-=20;
right=true;
left=false;
start=false;
}
}
if (key=='X')
{
if (sw==false)
{
thingX[0]+=20; thingX[1]+=20; thingX[2]+=20;
left=true;
right=false;
start=false;
}
}
}
}
void newThing(int i )
{
thingType[i] = int (random(3)+1) ;
thingX[i] = int(random(600)+1) ;
}
void draw1(int i)
{
if(newH>0)
{
tint(255, 255-z2);
image(img1,thingX[i],300, newH, newH);
}
}
void draw2(int i)
{
if(newH2>0)
{
tint(255, 255-z3);
image(img2,thingX[i],300, newH2, newH2);
}
}
void draw3(int i)
{
if(newH3>0)
{
tint(255, 255-z4);
image(img3,thingX[i],300, newH3, newH3);
}
}
void stop()
{
player.close();
minim.stop();
super.stop();
}
void drawMan()
{
if (start==true)
{
tint(255, 255);
image(imgMan, 300,450,newH4,newH4);
}
if (right==true)
{
tint(255, 255);
image(rightwalk, 300,450,newH4,newH4);
}
if (left==true)
{
tint(255, 255);
image(leftwalk, 300,450,newH4,newH4);
}
}
void player()
{
player.loop();
}
沒有留言:
張貼留言