做水果忍者!!!
先去找圖片然後丟到processing裡面
並且讓它顯示出來
之後讓西瓜能夠自由落下
之後試著讓西瓜能由下往上隨機生成且往左或右
並且碰到西瓜,西瓜就最消失
———————————————————————————————————————
PImage img;float x=100,y=500,vx=5,vy=-25;
int fruitDie=0;//水果還沒死掉
void setup(){
size(500,500);
img = loadImage("watermelon.png");
}
void draw(){
background(2);
image(img,x,y,150,100);
x+=vx; y+=vy;
vy+=0.89;
if(y>500) fruitDie=1;
if(x<mouseX && mouseX<x+150 && 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;//西瓜復活!
}
}
———————————————————————————————————————
來學播聲音ㄜ
先找音樂丟進processing裡面
加入函式庫
之後打上程式碼
這邊直接給你附上辣!
———————————————————————————————————————
/*import processing.sound.*;
SoundFile sound1;
SoundFile sound2;*/
import ddf.minim.*;
Minim minim;
AudioPlayer player1;
AudioPlayer player2;
void setup(){
/*size(300,300);
sound1 = new SoundFile(this, "Sword-swipe-3.wav");
sound2 = new SoundFile(this, "Throw-fruit.wav");
sound1.play();//播一次
sound2.loop();//循環播放*/
minim = new Minim(this);
player1 = minim.loadFile("Sword-swipe-3.wav");
//player2 = minim.loadFile("Throw-fruit.wav");
player1.loop();
}
void draw(){
}
void mousePressed(){
//sound1.play();
player1.rewind();
player1.play();
}
之後結合之前做的西瓜往上丟ㄉ程式碼
J邊一樣直接附上辣!
———————————————————————————————————————
import ddf.minim.*;
Minim minim;
AudioPlayer player1;
AudioPlayer player2;
PImage img;
float x=100,y=500,vx=5,vy=-25;
int fruitDie=0;//水果還沒死掉
void setup(){
size(500,500);
img = loadImage("watermelon.png");
minim = new Minim(this);
player1 = minim.loadFile("Sword-swipe-3.wav");
//player2 = minim.loadFile("Throw-fruit.wav");
player1.loop();
}
void draw(){
background(2);
image(img,x,y,150,100);
x+=vx; y+=vy;
vy+=0.89;
if(y>500) fruitDie=1;
if(x<mouseX && mouseX<x+150 && y<mouseY && mouseY<y+100) fruitDie=1;
player1.rewind();
player1.play();
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;//西瓜復活!
}
}
———————————————————————————————————————







沒有留言:
張貼留言