2021年1月7日 星期四

week05

 忍者切水果~是一個我很喜歡的遊戲!!

前面是利用上禮拜學的拉入圖檔.

PImage img;
float x=100, y=200;
void setup(){
  size(500,500);
  img = loadImage("fruit.png");
}
void draw(){
  image(img, x, y,100,100);
}
然後利用上禮拜學的牛頓運動定律!
PImage img;
float x=100, y=500,vx=3,vy=-30;
void setup(){
  size(500,500);
  img = loadImage("fruit.png");
}
void draw(){
  image(img, x, y,100,100);
  x += vx;
  y += vy;
  vy += 0.98;
}//讓水果拋物線運動.

左右彈跳則:
PImage img;
float x=100, y=500,vx=3,vy=-30;//(x,y)座標
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){
    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);
    }
  }
}
接著是最重要的切水果~
PImage img;
float x=100, y=500,vx=3,vy=-30;//(x,y)座標
int fruitDie=0;//一開始水果還在
void setup(){
  size(500,500);
  img = loadImage("fruit.png");
}
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;
  }
}
接著丟入音效:
import processing.sound.*;//使用聲音外掛
SoundFile sound1;//聲音的物件的變數
SoundFile sound2;
void setup(){
  size(300,300);
  sound1 = new SoundFile(this, "launch_dnmenu1.wa");
  sound2 = new SoundFile(this, "BULLET.wav");
  //sound1.play();//播一次
  sound2.loop();//循環播放
 }
 void draw(){
   
 }
 void mousePressed(){
   sound1.play();
 }


沒有留言:

張貼留言