processing
import processing.serial.*;////
Serial myPort;////
int count=1800;
PImage candy;
PImage monster;
PImage bg;
PImage die;
PImage heart;
float [] candyX=new float[10];
float [] candyY=new float[10];
float monsterX=235, monsterY=450;
int score=150;
int h=0;
void setup() {
size(513, 615);
myPort = new Serial(this, "COM3", 9600);////
for (int i=0; i<10; i++) {
candyX[i] = random(70, 295);
candyY[i] = -i*100;
}
candy = loadImage("candy.png");///三角椎
monster = loadImage("monster.png");
bg = loadImage("bg.jpg");
die =loadImage("die.png");
}
float vx=0;
//float vy=0;
void draw() {
if (h==0) {
image(bg, 0, 0, 513, 615);
//background(255);
//monsterX=mouseX-47;
while (myPort.available()>=1)
{
int x = myPort.read();
///int y = myPort.read();
//int sw = myPort.read();
vx= (x-128)/32;
// vy=(y-128)/32;
println(vx);
//monsterY=y;
}
monsterX += vx;
// monsterY += vy;
for (int i=0; i<7; i++) {
image(candy, candyX[i], candyY[i], 60, 60);
candyY[i]+=2;
if (candyY[i]>615)
{
candyY[i]=-300; //-183
candyX[i]=random(70, 295);///三角錐重生
}
if (candyY[i]+60>monsterY) {
if (monsterX<candyX[i]+58 && candyX[i]<monsterX+48) //2cm
{///車碰到三角錐
score+=10;
candyY[i]=-150;
}
}
}
if (count<0) {
background(0, 0, 0);
h=1;
} else {
count--;
}
textSize(50);
fill(25, 25, 250, 250);
text("Time: "+int(count/60), 250, 50);
textSize(50);
text(score, 50, 100);
}
if (count<0 || score<1000)
{
h=1;
image(die, -35, 100, 600, 350);
}
}
void keyPressed() {
count=1800;
if (keyCode == ENTER)
{
h=0;
score=150;
}
}
沒有留言:
張貼留言