import processing.serial.*;
Serial serial;
int val;
float [] X=new float [10], Y= new float[10];
PImage plane;
PImage sky;
PImage moster,row,row2,row3,row4;
int count=0;
int score=0;
int n=(int)random(5);
void setup()
{
background(255,255,255);
size(600,400);
serial=new Serial(this,"COM3",9600);
plane=loadImage("plane.gif");
moster=loadImage("moster.jpg");
sky=loadImage("sky.jpg");
row = loadImage("1.png");
for(int i=0;i<10;i++){
newb(i);
drawbanana(i);
}
}
void keyPressed(){
/*if(keyCode==UP) now+=10;
if(keyCode==DOWN) now-=10;
if(keyCode==LEFT) no+=10;
if(keyCode==RIGHT) no-=10;
if(keyCode==32)
{
if((X[0]+no)>250 && (X[0]+no)<350 && (Y[0]+now)<250 && (Y[0]+now)>150) {
print("哈哈哈");
score+=10;
print(score);
X[0]=random(200)+200;
Y[0]=random(400);
}
}*/
}
int now=0;
int no=0;
void draw()
{
if(serial.available()>0){
int val=serial.read();
if(val=='1') now+=10;
if(val=='2') now-=10;
if(val=='3') no+=10;
if(val=='4') no-=10;
if(val=='5')
{
if((X[0]+no)>250 && (X[0]+no)<350 && (Y[0]+now)<250 && (Y[0]+now)>150) {
print("哈哈哈");
score+=10;
print(score);
X[0]=random(200)+200;
Y[0]=random(400);
}
}
print(val);
}
background(255);
int m=millis();
int p=(60000-m)/1000;
if(m<60000){
background(255);
for(int i=0;i<n+1;i++){
drawbanana(i);
if(count%1000==0){
newb(i);
n=(int)random(1);
}
//image(moster,300+no,200+now,50,80);
image(plane,300,200,600,400);
fill(255,0,0);
text("Score:"+score,10,30,100,100);
textSize(20);
imageMode(CENTER);
// if(dist(300,200,X[0],Y[0]) - dist(300,200,X[100],Y[100])) image(row,200,200,50,50);
}
count++;
text("TIME:"+p,500,30,100,100);
println(n);
}
else{
background(255);
fill(255,0,0);
text("Score:"+score, 200,150,400,100);
textSize(40);
text("TIME UP", 200, 200 ,200,500);
}
}
void drawbanana(int i){
image(sky,X[i]+no, Y[i]+now, 3600, 3400);
image(moster,X[i]+no, Y[i]+now, 50, 80);
}
void newb(int i){
X[i]=random(200)+200;
Y[i]=random(400);
}
沒有留言:
張貼留言