2015年1月18日 星期日

Final(打殭屍加強版)-接蘋果遊戲




倒數 開始
左上角倒數計時30秒
紅蘋果,一顆1分
得30分後 有綠蘋果,一顆2分
畫面中由左到右籃子 分別對應8個按鍵
遊戲結束後 算總分

import ddf.minim.*;
Minim m;
AudioPlayer player;
int []bz=new int[1000];
PImage imgZombie;
PImage imgRZombie;
PImage imgShoot;
PImage imgBG;

import processing.serial.*;
Serial myPort;  // Create object from Serial class
int val;

void setup() {

  size(800, 600);
  imgZombie=loadImage("apple01.png");
  imgRZombie=loadImage("apple02.png");
  imgShoot=loadImage("shoot.png");
  imgBG=loadImage("sky.png");
  for (int i=0;i<1000;i++) {
    bz[i]=int(random(8));

  }


  m = new Minim(this);
  player = m.loadFile("apple.mp3");
  //player.play();
 
  String [] all = Serial.list();
  String portName = all[all.length-1];
      player.play();
  myPort = new Serial(this, portName, 9600);
}

int now=0;
int a;
int total=0;
int countDown=300;
int countDown2=1860;//1860

void draw() { 
  background(imgBG);
 
   print("val=" + val);

  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  } 
 
  int a=0;
  if (a==0) {
    if (countDown>0) {
      countDown--;
      textSize(100);
      text(countDown/30+"Seconds", 200, 300);
      return;
    }
    a++;
  }
 
  if (a==1) { 

    if (countDown2>0) {
      countDown2--;
      textSize(50);
      text(countDown2/60+"Second", 20, 40);
      for (int i=now;i<now+5;i++) {
        if (now<=30)image(imgZombie, bz[i]*100, 400-(i-now)*100);
        if (now>30)image(imgRZombie, bz[i]*100, 400-(i-now)*100);
      }
      image(imgShoot, 0, 500);
      image(imgShoot, 100, 500);
      image(imgShoot, 200, 500);
      image(imgShoot, 300, 500);
      image(imgShoot, 400, 500);
      image(imgShoot, 500, 500);
      image(imgShoot, 600, 500);
      image(imgShoot, 700, 500);
    }
    a++;
  }
 
  if (a==2) {
    if (countDown2/60==0)text("Score:"+total, 300, 350);
  }
 
    if (val-48==bz[now])
  {
    if (total<50)a=1;
    if (total==50)a=2;
    if (countDown2/60==0)a=0;
    now++;
    total=total+a;
  }
}

/*void keyPressed(int val) {

  //if (val==bz[now])
  //{
  //  if (total<50)a=1;
  //  if (total==50)a=2;
   // if (countDown2/60==0)a=0;
  //  now++;
  //  total=total+a;
 // }
 
}*/

沒有留言:

張貼留言