2013年12月16日 星期一

譚庚倫的15周作業

                                                     小朋友下樓梯之破壞樓梯




程式碼:
import ddf.minim.*;
//import processing .serial.*;
int t=0;
//Serial serial
int s=0;
int time=0;
int score=0;
String text="score:";   
String text1="get score:";
int []sequence=new int[1000];
int []thingx = new int[100];
int []thingy = new int[100];
PImage floor, bg, man, over, man2,pupu;
int pux;
float puy;
int manx=213;
float many=0;
Minim m;
AudioPlayer player, player1, player2,player3;


void setup() {
  m=new Minim(this);
 // serial= new Serial(this,"COM3",9600);
  for (int i =0;i<10;i++) {
  }
  player=m.loadFile("down.wav");
  player1=m.loadFile("die.wav");
  player2=m.loadFile("back.mp3");
  player3=m.loadFile("bom.wav");
  man2=loadImage("man2.png");

  size(426, 311);
   pupu=loadImage("pupu.png");
  over=loadImage("gameover.jpg");
  floor=loadImage("floor.jpg");
  man=loadImage("man.png");
  bg=loadImage("bg.jpg");
  for (int i=0;i<10;i++) {
    sequence[i] = int(random(3));
  }
  for (int i=0;i<10;i++) {
    thingx[i] = int(random(426));
    thingy[i] = int(random(1000));
  }

   
     
}
int now=0;
int x=0;
void draw() {
  background(bg);
  image(man, manx, many, 50, 50);
  //if(serial.availabe()>0)
  //{
   // char c=serial.read();
   // print(C);
//  }


  //player2.play();
  if(key=='a' && keyPressed==true){
    t=1;
    pux=manx;
    puy=many;
  
  }
   if(t==1)
  {
    puy=puy+3;
  image(pupu,pux, puy, 20, 20);
  }

  
  for (int i=0;i<10;i++) {
    if(s==0)
    {

    image(floor, thingx[i], thingy[i]);
    thingy[i]-=1; 
    if (thingy[i]==0)
    {
      thingy[i]=311;
    }
    if(dist(thingx[i]+48.5,thingy[i]+10,pux,puy)<=40)
    {
      //player3.play();
      thingy[i]=330;
      pux=312;
      puy=312;
     
      
   }
    // float dis=dist(thingx[i],thingy[i],manx,many);
    if (dist(thingx[i]+48.5, thingy[i]+10, manx, many)<=67.5) {
      
      image(man2, manx, many, 50, 50);

      //image(man2,manx,many,50,50);
      many=thingy[i]-42;
    }

    else {
many+=0.1;
    }
    }
    
    if (many>311)
    {  
       s=1;
      image(over, 100, 105.5, 250, 100);
      many+=10;
      //player.play();
    }
    if (many<0)
    {
      s=1;
      image(over, 100, 105.5, 250, 100);
     
    }
  }
  
if(s==0){
 if(time%50==0)
 {
score+=10;   
print(score);  
 }
 textSize(32);
   fill(200);
  text(text,40,40);
  textSize(32);
   fill(200);
  text(score,130,40);
}
else
{
  textSize(32);
   fill(200);
  text(text1,60,250);
  textSize(32);
   fill(200);
  text(score,250,250);
  
}
time++;
  

}


void keyPressed() {

  //if(keyCode==DOWN)many+=2;
  if (keyCode==LEFT)manx-=10;
  if (keyCode==RIGHT)manx+=10;
  
}


沒有留言:

張貼留言