2020/10/12
(一)fruit_cut
運用PImage和位置概念,仿作切水果遊戲
ppt去背: https://officeguide.cc/powerpoint-image-remove-background-tutorial/
//fruit_cut
PImage img;
float x=100,y=500,vx=3,vy=-30;
void setup(){
size(500,500);
img=loadImage("banana.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);
}
}
}
------------------------------------------------------------------------------
//fruit_cut
import processing.sound.*;
SoundFile file;
PImage img;
float x=100,y=500,vx=3,vy=-30;
int fruitDie=0;
void setup(){
size(500,500);
img=loadImage("banana.png");
//file = new SoundFile(this, "damage6.mp3");
//file.play();
}
void draw(){
background(255);
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){
file = new SoundFile(this, "damage6.mp3");
file.play();
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;
}
}
沒有留言:
張貼留言