2014年6月23日 星期一

期末作品

阿蛤過橋

起始畫面:


















import ddf.minim.*;
Minim minim;
AudioPlayer song;
PImage land, man, bg, ho;
int countDown=7*30;
void setup() {
  size(500, 400);
  minim = new Minim(this);
  song = minim.loadFile("C:/Users/Jean/Desktop/final/sky.mp3");
  song.play();
  music();
  land = loadImage("C:/Users/Jean/Desktop/final/land.jpg");
  man = loadImage("C:/Users/Jean/Desktop/final/man.png");
  bg=loadImage("C:/Users/Jean/Desktop/final/bk.jpg");
  ho=loadImage("C:/Users/Jean/Desktop/final/home.jpg");
}
boolean bMoving=false;
int woodline, w1, w2;
int manX=0;
int manY;
float landX;
float landXX;
int stage=1;
int state;
int level=1;
void draw() {
  if (countDown>0)
  {
    background(ho);
    countDown--;  
    return;
  }
  background(bg);
  image(land, 0, 350, 50, 50);
  image(land, 400, 350, landXX, 50);
  fill(0);
  textSize(20);
  text("LEVEL  "+level, 400, 50);
  if (stage==1)
  {
    change();
    stage+=1;
  }  
  if (stage==3)
  {  
    fill(0);
    textSize(100);
    text("LOSE !", 50, 100);
    song.close();
    song = minim.loadFile("C:/Users/Jean/Desktop/final/lose.mp3");
    song.play();
    noLoop();
  }
  if (bMoving==true)
  {
    if (manX<=(-woodline))
    {

    image(man, manX, 300, 50, 50);
    manX+=3;
    translate(260, 280);
    rotate(PI/2);
    rect(50, 200, 10, woodline);
    }
    else
    {
      bMoving=false;
    }
  }
  if (bMoving==false)
  {
    image(man, manX, 300, 50, 50);
    if ((manX>=360)&&(manX<=360+landXX))
    {
     translate(260, 280);
    rotate(PI/2);
    rect(50, 200, 10, woodline);
      manX=0;
      stage=1;
      woodline=0;
      level++;
      println("win");
    }
    else if ((manX>50)&&(manX<400))
    {
      translate(260, 280);
      rotate(PI/2);
      rect(50, 200, 10, woodline);
      println("lose");
      level=1;
      stage=3;
    }
  }
}

void keyPressed() {
  if (keyCode==LEFT) {
    rect(50, 350, 10, woodline);
    woodline-=5;
  }
  if (keyCode==RIGHT) {
    bMoving=true;
    translate(260, 280);
    rotate(PI/2);
    rect(50, 200, 10, woodline);
  }
}
void music()
{
  song.loop();
}
void  change()
{
  landXX=random(300);
  image(land, 0, 350, 50, 50);
  image(land, 400, 200, landXX, 50);
}
void stop()
{
  song.close();
  minim.stop();
}

沒有留言:

張貼留言