體感互動遊戲製作期中作品DEMO
傑克與魔豆(MoDo)
開發工具:Processing + Leap Motion
遊戲畫面
畫面的左上方增加當前掉落蘋果核數量、右上方則為公尺數及計分板
遊戲會隨公尺數的增高,增加掉落的蘋果核數量
過程及步驟
程式碼
import ddf.minim.*;
AudioPlayer player;
Minim minim;
import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage[]imgPeople=new PImage[2];
PImage imgApple;
PImage[]imgBG=new PImage[3];
int BGM=0;
float peopleX=300,peopleY=50;
float[]appleX=new float[100];
float[]appleY=new float[100];
int peopleI=0;
int appleI=1;
int hit=80;
int gameOver=0;
float BGmoveY=0;
float APmoveY=0;
void setup()
{
size(650,600);
background(255,255,0);
noStroke(); fill(50);
leap = new LeapMotion(this);
minim = new Minim(this);
player = minim.loadFile("start.mp3");
player.play();
imgPeople[0]=loadImage("P1.png");
imgPeople[1]=loadImage("P2.png");
imageMode(CENTER);
imgBG[1]=loadImage("BG2.png");
imgBG[0]=loadImage("BG1.png");
imgBG[2]=loadImage("BG3.png");
image(imgBG[0],330,300);
image(imgBG[2],330,525);
textSize(140);
fill(255,105,0);
text("Mo",10,468);
text("Do",460,472);
imgApple=loadImage("A1.png");
//draw apples
for(int i=0;i<appleI;i++)
{
newApple(i);
}
}
//apple random
void newApple(int i)
{
appleY[i]=-random(200);
appleX[i]=random(650);
}
void draw()
{
if(gameOver==1)
{
noLoop();//void draw stop
background(255,0,0);
player.close();//modo.mp3 close
player = minim.loadFile("GG.mp3");
player.play();
//Show Score
textFont(createFont("calibri",40));
textSize(60);
fill(255);
text("Game Over",200,200);
text(BGmoveY/100+" m",250,300);
println("GAMEOVER");
return;
}
int fps = leap.getFrameRate();
// HANDS get then gamestart
for(Hand hand : leap.getHands())
{
//change BGM
if(BGM==0)
{
player.close();//close start.mp3
BGM=1;
}
if(BGM==1)
{
player = minim.loadFile("modo.mp3");//just run once
player.play();
BGM=3;
}
//leapHand's value include
int hand_id = hand.getId();
PVector hand_position = hand.getPosition();
PVector hand_stabilized = hand.getStabilizedPosition();
PVector hand_direction = hand.getDirection();
PVector hand_dynamics = hand.getDynamics();
float hand_roll = hand.getRoll();
float hand_pitch = hand.getPitch();
float hand_yaw = hand.getYaw();
float hand_time = hand.getTimeVisible();
PVector sphere_position = hand.getSpherePosition();
float sphere_radius = hand.getSphereRadius();
background(255,255,0);
drawBG();
//People0,1 change & move
image(imgPeople[peopleI/10],hand_position.x,peopleY=450);
println("PEOPLE MOVE");
peopleI++;
if(peopleI>=19)peopleI=0;
//Apple draw & move
for(int i=0;i<appleI;i++)
{
image(imgApple,appleX[i],appleY[i],40,60);
appleY[i]+=4;
if(appleY[i]>600)newApple(i);
println("APPLE\n");
//gameOver yes or no
if(dist(hand_position.x,peopleY,appleX[i],appleY[i])<hit)
{
gameOver=1;
}
}
//Apple more and more
appleMore(BGmoveY);
}
}
float appleMore(float x)
{
if(x/100>20) appleI=2;
if(x/100>40) appleI=4;
if(x/100>80) appleI=6;
if(x/100>120) appleI=8;
if(x/100>170) appleI=10;
if(x/100>200) appleI=12;
return x;
}
//BG move
void drawBG()
{
int s=int(BGmoveY)/100;
for(int i=0;i<10;i++)
{
image(imgBG[1],330,i*210 + BGmoveY%210);
}
BGmoveY+=5;
//Count Score
textFont(createFont("calibri",60));
textSize(50);
fill(255,105,0);
text("APPLE:",14,40);
text(appleI,166,40);
text(s,525,41);
text(" m",600,40);
println("BG DRAW");
}
void leapOnInit(){
// println("Leap Motion Init");
}
void leapOnConnect(){
// println("Leap Motion Connect");
}
void leapOnFrame(){
// println("Leap Motion Frame");
}
void leapOnDisconnect(){
// println("Leap Motion Disconnect");
}
void leapOnExit(){
// println("Leap Motion Exit");
}
心得







沒有留言:
張貼留言