PImage egg;
float[] eggX=new float[100];
float[] eggY=new float[100];
boolean[] eggDie=new boolean[100];
void setup() {
size(800, 600);
egg = loadImage("egg.png");
for (int i=0; i<9; i++) imgN[i] = loadImage(i+".png");
for (int i=0; i<100; i++) {
eggX[i]=random(100, 700);
eggY[i]=-random(2000);
eggDie[i]=false;
}
}
int score =0;
void draw() {
background(255);
fill(255);
rect(mouseX-50, mouseY-25, 100, 50);
for (int i=0; i<100; i++) {
if (eggDie[i])continue;
image(egg, eggX[i], eggY[i], 80, 100);
eggY[i]+=5;
if (eggY[i]>700)eggY[i]=-2000+600;
if (dist(mouseX-50, mouseY-25, eggX[i], eggY[i])<50) {
eggDie[i]=true;
score+=100;
}
}
//fill(255, 0, 0);textSize(80);text("Score:"+score, 100, 100);
int now=score;
for (int i=0; i<7; i++) {
image(imgN[(now%10)], 400-i*100, 100, 100, 150);
now/=10;
}
}
PImage []img=new PImage[8];
//float cherryX=0, cherryY=700;
//float cherryVX=6, cherryVY=-40;
float [] cherryX=new float[8];
float [] cherryY=new float[8];
float [] cherryVX=new float[8];
float [] cherryVY=new float[8];
void setup() {
size(800, 600);
for (int i=0; i<8; i++)img[i]=loadImage("cherry.png");
for (int i=0; i<10; i++)sword[i]=new PVector();
for (int i=0; i<8; i++) {
cherryX[i]=random(3, 4);
cherryY[i]=-random(8);
}
}
PVector [] sword=new PVector[10];
void draw() {
background(255);
for (int i=0; i<8; i++) {
image(img[i], cherryX[i], cherryY[i], 150, 150);
cherryX[i]=random(3, 4);
cherryY[i]=-random(8);
cherryX[i]+=cherryVX[i];
cherryY[i]+=cherryVY[i];
cherryVY[i]+=0.98;
}
for (int i=9; i>0; i--) {
sword[i].x=sword[i-1].x;
sword[i].y=sword[i-1].y;
}
sword[0].x=mouseX;
sword[0].y=mouseY;
for (int i=1; i<10; i++) {
line(sword[i].x, sword[i].y, sword[i-1].x, sword[i-1].y);
}
}
沒有留言:
張貼留言