水果忍者
import SimpleOpenNI.*;
SimpleOpenNI openni;
class Fruit{
float X,Y,VX,VY;
Fruit (float x,float y,float vx,float vy){
X=x; Y=y; VX=vx; VY=vy;
}
void draw() {
background(255);(加入會變白的)
ellipse(X,Y,50,50);
}
void update(){
X+=VX; Y+=VY; VY+=1.98;
if(X<-100 || X>740 || Y<-100 || Y>580){
X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30);
}
}
}
Fruit fruit[] = new Fruit[20];
void setup() {
size(640, 480);
openni = new SimpleOpenNI(this);
openni.enableDepth();
openni.enableUser();
for(int i=0;i<20;i++)
fruit[i]= new Fruit( random(640), random(240),random(30)-15,-random(30));
}
void draw() {
openni.update();
image(openni.userImage(),0,0);
for(int i=0;i<20;i++){
fruit[i].draw();
fruit[i].update();
}
}
沒有留言:
張貼留言