2. 新增了jump 與 掉落的判斷
3. 困難 : get()函式取得的顏色 與 小畫家內顯示的顏色不同 造成無法用顏色判斷停止掉落
必須用座標點寫死
程式碼 :
import SimpleOpenNI.*;
PImage imgBG, imgBlend, imgUser,player;
int PX=100,PY=340;
int jumpN=1;
float PVY=0,PGY=0,move;
int stage=1;
color c1,c2,c3;
SimpleOpenNI openni;
void setup() {
size(640+640, 480);
imgBG=loadImage("imgBG3.jpg");
player=loadImage("player1.jpg");
imgBlend=createImage(640, 480, ARGB);
imgBlend.loadPixels();
//player.loadPixels();
imgBlend.updatePixels();
openni= new SimpleOpenNI(this);
openni.enableDepth();
openni.enableUser();
}
void draw() {
background(0);
openni.update();
image(imgBG, 0, 0);//background(imgBG);
image(imgBlend, 0, 0);
imgUser = openni.userImage();
image(imgUser, 640, 0);
imgBlend.loadPixels();
imgUser.loadPixels();
move=random(20)+1;
image(player,PX,PY);
for (int i=0;i<640*480;i++) {
color now=imgUser.pixels[i];
if (!(red(now)==blue(now) && blue(now)==green(now))) imgBlend.pixels[i]=color(255, 255, 0, 0);
// else imgBlend.pixels[i] = color(0,0,0);
}
c1 = get(PX-31,PY);
c2 = get(PX+31,PY);
c3 = get(PX,PY);
PY += PVY;
PVY += PGY;
if (PX>242 && PY>170 && PX<300) {PY+=5;}
if (PX<242 && PY> 340 || PX>300 && PY>340 )
{
PVY=0;
PGY=0;
jumpN=1;
}
// if (stage ==1 && c1 ==color(0,0,0) && c2 == color(0,0,0)) PY+=5;
imgBlend.updatePixels();
}
void keyPressed()
{
if (stage==1 && keyCode==RIGHT){ stage=1; PX+=move; }
if (stage==1 && keyCode==LEFT) { stage=1; PX-=move; }
if (stage==1 && keyCode==UP)
{
if (jumpN>0)
{
PVY=-6;
PGY=0.098*2;
jumpN--;
}
}
}
起跳
掉落


沒有留言:
張貼留言