2.有加速機制
PImage imgball, imgtrash, imgbomb, imgbasket;
int N = 4;
float []ballX = new float[N], ballY = new float[N], ballType = new float[N];
int a=0, b=0;
void setup() {
size(600, 600);
imgball = loadImage("baseketball.png");
imgtrash = loadImage("trash.png");
imgbomb = loadImage("bomb.png");
imgbasket = loadImage("basket.png");
for (int i = 0; i < N ; i++) {
newBall(i);
}
}
int countDown = 4*40;
int countDown2 = 60*40;
void draw() {
if ( countDown > 0 ) {
background(255, 0, 0);
countDown--;
textSize(60);
text("READY"+ countDown/40, 200, 250);
return ;
}
if ( b == 0 && countDown2 > 0 ) {
countDown2--;
background(#2B85DE);
for (int i=0 ; i<N ; i++) {
if ( ballType[i] == 1 ) drawGood(i);
else if (ballType[i] == 2 ) drawBad(i);
else if (ballType[i] == 3 ) drawTrash(i);
if( countDown2/40 >= 40 ){
ballY[i] += 4;
}
else if( countDown2/40 >= 30 ){
ballY[i] += 6;
}
else if( countDown2/40 >= 15 ){
ballY[i] += 8;
}
else if( countDown2/40 >= 15 ){
ballY[i] += 12;
}
else
ballY[i] += 14;
if ( ballY[i] >= 500 && ballY[i] <= 512 && ballX[i] >= (mouseX-50) && ballX[i] <= mouseX+50 ) {
ballY[i] = 601;
if ( ballType[i] == 1 ) {
background(255, 0, 0);
a++;
}
if ( ballType[i] == 2 ) {
b=1;
}
if ( ballType[i] == 3 ) {
a--;
}
}
fill(0);
textSize(32);
text("SCORE:", 410, 40);
fill(255, 0, 0);
textSize(45);
text(a, 530, 45);
fill(0);
textSize(45);
text("Time:"+ countDown2/40, 0, 50);
if ( ballY[i] > 600 ) newBall(i);
}
image( imgbasket, mouseX, 500, 50, 50);
//image(imgbasket, basketX, basketY, 50, 50); // keyboard control
//}
}
else {
background(0);
fill(255);
textSize(80);
text("GAME", 200, 180);
text("OVER", 200, 280);
fill(240, 0, 0);
text("grade:", 140, 380);
text(a, 410, 380);
}
}
/*void keyPressed(){
if(keyCode == UP) basketY -= 10;
if(keyCode == DOWN) basketY += 10;
if(keyCode == RIGHT) basketX += 10;
if(keyCode == LEFT) basketX -= 10;
}*/
void newBall(int i) {
ballY[i] = -random(500)+100;
ballX[i] = int(random(10))*60;
ballType[i] = int(random(3))+1;
}
void drawGood(int i) {
image( imgball, ballX[i], ballY[i], 50, 50);
}
void drawBad(int i) {
image( imgbomb, ballX[i], ballY[i], 50, 50);
}
void drawTrash(int i) {
image( imgtrash, ballX[i], ballY[i], 50, 50);
}
沒有留言:
張貼留言