Processing程式碼:
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
myPort = new Serial(this, "COM4", 9600);
imgPub=loadImage("Pub.jpg");
imgMusic=loadImage("Music.jpg");
imgPop=loadImage("Pop.jpg");
image(imgPop,400,600);
image(imgMusic,400,600);
image(imgPub,400,600);
bg = loadImage("background.jpg");
blue = loadImage("blue.jpg");
orange = loadImage("orange.gif");
green = loadImage("green.jpg");
blue1 = loadImage("blue1.gif");
orange1 = loadImage("orange1.jpg");
m = new Minim(this);
player = m.loadFile("DNA.mp3");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
player.play();
val = myPort.read();
image(imgPop,0,0,400,600);
if(keyPressed)
textSize(40);
text("Start!!", 250, 300);
if(key=='s')
image(imgMusic,0,0,400,600);
if(countDown>0){
//background(255,0,255);
countDown--;
text("Time: "+countDown/50,170,300);
return;
}
image(bg,0,0, 400,600);
image(blue,0,575,80,40);
image(orange,80,575,80,40);
image(green,160,575,80,40);
image(blue1,240,575,80,40);
image(orange1,320,575,80,40);
for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblue(i);
//if (keyPressed)
//if(key=='d'|| key=='D')
println(val);
if(525<thingY[i] && thingY[i]<700 && val==50)
{
thingY[i] = 650; grade+=100; //println(grade);
fill(#0046FF,90);
rect(0,575,80,-600);
}
}
else if(thingType[i]==2)
{
draworange(i);
//if (keyPressed)
{
//if(key=='f'|| key=='F')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==51)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(80,575,80,-600);
}
}
}
else if(thingType[i]==3)
{
drawgreen(i);
//if (keyPressed)
{
//if(key=='b'|| key=='B')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==52)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#10FF00,90);
rect(160,575,80,-600);
}
}
}
else if(thingType[i]==4)
{
drawblue1(i);
//if (keyPressed)
{
//if(key=='k'|| key=='K')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==49)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#0046FF,90);
rect(240,575,80,-600);
}
}
}
else if(thingType[i]==5)
{
draworange1(i);
//if (keyPressed)
{
//if(key=='j'|| key=='J')
println(val);
if (525<thingY[i] && thingY[i]<600 && val==53)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(320,575,80,-600);
}
}
}
thingY[i]+=3;
if(thingY[i]>600) newThing(i);
}
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
//background(#FF0015);
//background(imgMusic,400,600);
image(imgMusic,0,0,400,600);
fill(255,0,0);
text("Score: "+grade,122,300);
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblue(int i){
thingX[i]=int(random(0,0));
image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
thingX[i]=int(random(80,80));
image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
thingX[i]=int(random(160,160));
image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
thingX[i]=int(random(240,240));
image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
thingX[i]=int(random(320,320));
image(orange1,thingX[i],thingY[i],80,22);
}
沒有留言:
張貼留言