Serial myPort;
PImage over;
float [] cubeY=new float [17];
void setup() {
size(800, 300);
for (int i=0;i<16;i++) {
cubeY[i]=random(140, 170);
}
myPort = new Serial(this, "COM4", 9600);
over = loadImage("gameover.png");
}
int posY = 0;
int a = 0;
int q=1;
void draw() {
background(255);
if (a==0) {
textSize(50);
text("press the button to START", 80, 160);
fill(0, 102, 153, 500);
}
if (keyPressed == true) a=1;
if (a==1) {
fill(0, 0, 255);
ellipse(70, posY+40, 40, 40);
fill(0);
for (int m=0;m<16;m++) {
rect(m*50-q, 0, 50, cubeY[m]);
rect(m*50-q, cubeY[m]+50, 50, 250-cubeY[m]);
//if(cubeY[m]+50<0); cubeX+=850;
}
q++;
if (myPort.available()>0) {
posY = myPort.read();
println(posY);
}
if (posY+20<60 | posY+60>240) {
image(over, 0, 0, 800, 300);
println("Game Over");
}
}
}


沒有留言:
張貼留言