PImage []imgFood2=new PImage[20];
PVector [] posFood=new PVector[20];
int [] liveFood=new int[20];
PImage imgFood;
int count=660;
void setup() {
size(800, 600);
imgFish=loadImage("fish.png");
imgFood=loadImage("food.png");
for (int i=0; i<20; i++) {
//imgFood2[i]=loadImage("food.png");
posFood[i]=new PVector(-100, -100);
liveFood[i]=-1;
}
}
float fishX=500, fishY=500, foodX=500, foodY=500;
int eatCount=180;
void draw() {
// random(fishX);
//random(fishY);
background(51, 230, 204);
rect(0, 500, 800, 100);
fill(161, 107, 71);
image(imgFish, fishX, fishY, 100, 100);
//image(imgFood, foodX, foodY, 40, 40);
for (int i=0; i<20; i++) {
if (liveFood[i]>=0) {
posFood[i].y++;
image(imgFood, posFood[i].x, posFood[i].y, 40, 40);
liveFood[i]--;
}
}
if (fishY<foodY)
fishY=fishY+2;
if (fishY>foodY)
fishY=fishY-2;
if (fishX<foodX)
fishX=fishX+2;
if (fishX>foodX)
fishX=fishX-2;
// if(fishY==foodY&&fishX==foodX)
//foodY=-50;
if (abs(fishY-foodY)<3&&abs(fishX-foodX)<3)
{
foodY=random(400);
foodX=random(800);
} else {
if (foodY<500)
foodY++;
}
}
void mousePressed() {
for (int i=0; i<20; i++) {
if (liveFood[i]==-1) {
posFood[i].x=mouseX;
posFood[i].y=mouseY;
liveFood[i]=300;
println(i);
break;
}
}
//foodX=mouseX;
//foodY=mouseY;
}
沒有留言:
張貼留言