第二步驟_拋物線
第三步驟_隨機產生
第四步驟_砍水果
第五步驟_加音效
import processing.sound.*;
SoundFile sound1;
SoundFile sound2;
PImage img;
float x=100, y=100 , vx=3, vy=-30;
int fruitDie=0;
void setup(){
size(500,500);
img = loadImage("fruit.png");
sound1 = new SoundFile(this,"stabbing.mp3");
sound2 = new SoundFile(this,"summer.mp3");
///sound1.play();
sound2.loop();
}
void draw(){
image(img,x,y,100,100);
x+=vx;
y+=vy;
vy+=0.98;
if(y>500){///下一步驟會改
if(y>500)fruitDie=1;
if(x<mouseX && mouseX<x+100 && y<mouseY && mouseY<y+100)fruitDie=1;
stroke(255);line(mouseX,mouseY,pmouseX,pmouseY);///白色刀子
if(fruitDie==1){
if(frameCount%2==0){
x=random(250);y=500; vx=random(2,3);vy=random(28,32);
}
else{
x=random(250,500);y=500; vx=-random(2,3);vy=-random(28,32);
}
}
fruitDie=0;
}
}///
}
void mousePressed(){
sound1.play();
}
PImage img;
float x=100, y=100 , vx=3, vy=-30;
int fruitDie=0;
void setup(){
size(500,500);
img = loadImage("fruit.png");
}
void draw(){
image(img,x,y,100,100);
x+=vx;
y+=vy;
vy+=0.98;
if(y>500)fruitDie=1;
if(x<mouseX && mouseX<x+100 && y<mouseY && mouseY<y+100)fruitDie=1;
stroke(255);line(mouseX,mouseY,pmouseX,pmouseY);///白色刀子
if(fruitDie==1){
if(frameCount%2==0){
x=random(250);
y=500;
vx=random(2,3);
vy=random(28,32);
}
else{
x=random(250,500);
y=500;
vx=-random(2,3);
vy=-random(28,32);
}
fruitDie=0;
}
}
加聲音
import processing.sound.*;
SoundFile sound1;
SoundFile sound2;
PImage img;
float x=100, y=100 , vx=3, vy=-30;
int fruitDie=0;
void setup(){
size(500,500);
img = loadImage("fruit.png");
sound1 = new SoundFile(this,"stabbing.mp3");
sound2 = new SoundFile(this,"summer.mp3");
///sound1.play();
sound2.loop();
}
void draw(){
background(0);
image(img,x,y,100,100);
x+=vx;
y+=vy;
vy+=0.98;
if(y>500)fruitDie=1;
if(x<mouseX && mouseX<x+100 && y<mouseY && mouseY<y+100)fruitDie=1;
stroke(255);line(mouseX,mouseY,pmouseX,pmouseY);///白色刀子
if(fruitDie==1){
if(frameCount%2==0){
x=random(250);
y=500;
vx=random(2,3);
vy=random(28,32);
}
else{
x=random(250,500);
y=500;
vx=-random(2,3);
vy=-random(28,32);
}
fruitDie=0;
}
}
void mousePressed(){
sound1.play();
}
沒有留言:
張貼留言