2016年1月4日 星期一

160104_02160065劉劭玟02160323饒珮以_week17

Week17最後一週
最終Demo成果
我們這組做的是小丸子腳踏車

材料:

用了四個塑膠板加彈簧與按鈕
木板加報紙與鋁管連結樞紐














玩法:

腳踩踏板使小丸子前進
龍頭可控制行進軌道
必須避開障礙物
即可獲勝





Processing:

import ddf.minim.*;
import processing.serial.*;
int State=0, count=0;
PImage girl, girl1, road, start, line, win, fail;
PImage [] stone = new PImage [5];
int [] stone1 =new int [10];
int [] n =new int [6];
int time, k=5, type=0, a, sco;
Serial Port1;
Minim minim;
AudioPlayer in, up;
void setup()
{
  size(550, 700);
  girl=loadImage("red.png");
  girl1=loadImage("red1.png");
  start=loadImage("startface.png");
  road=loadImage("road.png");
  line=loadImage("line.png");
  win=loadImage("winpage.png");
  fail=loadImage("fail.jpg");

  minim = new Minim(this);
  in = minim.loadFile("2.mp3");
  up = minim.loadFile("1.mp3");
  for (int i=0; i<5; i++)
    stone[i]=loadImage("stone.png");
  Port1 = new Serial(this, "COM3", 9600);

  for (int i=0; i<4; i++)
  {
    stone1[i]=int(i*150)-10;
    n[i]=i;
  }
  n[4]=int(random(4));
  n[5]=int(random(4));
}

float Gx=300, Sl=-10, Sy1=-10, Sy2=-10, Sy3=-10, Sy4=-10, Sy5=-10;

void draw() {

  //in = minim.loadFile("2.mp3");
  //in.play();

  if (type==0)
  {
    image(start, 0, 0, 550, 700);
    fill(150, 255, 50);
    textSize(120);
    text("Bike", 50, 100);
    text("For", 80, 280);
    text("Your", 30, 380);
    text("Life", 100, 500);
  }

  if (Port1.available()>0) {
    State =Port1.read();
    if (State=='5')
      type=1;

    if (type==1)
    {

      image(road, 0, 0, 550, 700);
      if (count%2==0)
        image(girl, Gx, 550, 100, 150);
      else
        image(girl1, Gx, 550, 100, 150);


      if (count>210)
        image(line, 0, Sl+=k, 550, 120);
      image(stone[1], stone1[n[1]], 0+Sy1, 120, 120);
      if (count>30)
        image(stone[2], stone1[n[3]], 0+Sy2, 120, 120);
      if (count>60)
        image(stone[3], stone1[n[0]], 0+Sy3, 120, 120);
     // if (count>90)
       // image(stone[0], stone1[n[2]], 0+Sy4, 120, 120);


      a=timer();

      if (Sy1>=440&&stone1[n[1]]==Gx-10)
        type=2;
      if (Sy2>=440&&stone1[n[3]]==Gx-10)
        type=2;
      if (Sy3>=440&&stone1[n[0]]==Gx-10)
        type=2;
      if (Sy4>=440&&stone1[n[2]]==Gx-10)
        type=2;
       if (Sl>=440)
        type=3;




      if (State=='5'||State=='6')
      {
        Sy1+=k;
        up = minim.loadFile("1.mp3");
        up.play();

        if (count>30)
          Sy2+=k;
        if (count>60)
          Sy3+=k;
        if (count>190)
          Sy4+=k;
        if (count>200)
          Sy5+=k;

        count++;

        if (Sy1>650) {
          Sy1=-10;
          k=k+1;
        }
        if (Sy2>650) {
          Sy2=0;
          k=k+2;
        }
        if (Sy3>650) {
          Sy3=0;
          k=k+3;
        }
        if (Sy4>650) {
          Sy4=0;
          k=k+3;
        }
      }


      if (State=='1')
        Gx=450;
      if (State=='2')
        Gx=300;
      if (State=='3')
        Gx=150;
      if (State=='4')
        Gx=0;
    }
    if (type==2)
    {
      sco=a;
      image(fail, 0, 0, 550, 700);
      textSize(50);
      fill(200, 10, 100);
      text("GAME OVER", 260, 100);
      text("score: "+sco, 252, 180);
    }

    if (type==3)
    {
      sco=500-a;
      image(win, 0, 0, 550, 700);
      textSize(80);
      fill(150, 100, 100);
      text("YOU  WIN", 100, 80);
      text("score: "+sco, 120, 200);
    }
  }
}

int timer() {
  textSize(40);
  fill(100);
  text("time:"+int(time/60), 350, 50);
  time++;
  return time/60;
}


影片:





沒有留言:

張貼留言