2013年11月10日 星期日

Week10 張智棠,期中作品展示

期中作品展示


程式碼 :

import ddf.minim.*;
AudioPlayer playerDead,playerST1,playerending,playerST2;
Minim minim;
float loc = 0 ;
int  N = 10 ,score = 0,blood=100;
int PX=100,PY=701;
PImage coin , cone , fire,stageBG2,stageBG4,stageBG5,people,copyright,copyright2;
int []thingType = new int [10] ;
float []thingY = new float [10];
float []thingX = new float [10];
float HeadX=200,HeadY=600;
int stage = 1;
int shoes = 0,jumper=0;

void setup ()
{
  size (600, 800) ;
  coin = loadImage("coin.jpg") ;
  cone = loadImage("cone.jpg") ;
  fire = loadImage("image.jpg");
  stageBG4 = loadImage("gameover.jpg");
  stageBG2 = loadImage("stageBG2.bmp");
  people = loadImage("people.jpg");
  copyright = loadImage("copyright.bmp");
  copyright2 = loadImage("copyright2.bmp");
  for ( int i = 0 ; i < N ; i++)
  {
     newThing(i);
  }
  minim = new Minim(this);
  playerDead = minim.loadFile("warawa.mp3");
  playerST1 = minim.loadFile("ST1.mp3");
  playerST2 = minim.loadFile("ST2.mp3");
  playerending = minim.loadFile("ending.mp3");
 
}
int now = 0 ;
void draw ()
{
 
 if (stage==1)
 {
   playerST1.pause();
   playerDead.pause();
   background(255,255,255);
   image(people,150,450,30,58);
   fill(#1A1717);
   textSize(12);
   text("Matchstick Men are suffering from the strange thing!",100,100);
   text("He want to find he's friend to help him",100,200);
   textSize(25);
   text("Rule :",100,250);
   textSize(12);
   text("Catch TEN COIN can stop the strange thing for a while",100,300);
   text("Catech the other thing may cause a damage from himself",100,400);
   textSize(32);
   text("Press S or s to Play ", 150, 700);
 }
  if (stage==2)
  {
    background(255);
    playerST1.pause();
    playerST2.setGain(-20);
    playerST2.play();
   
    score = 0;
    blood = 100;

    image(stageBG2,0,0,600,800);
    image(people,PX,PY,30,58);
   
    if (150<PX&&PX<250&&550<PY&&PY<650)
    {
      shoes=1;
      textSize(25);
      text("You Get a shoes!",200,500);
      text("Triple MoveSpeed!",200,600);
    }
    if (300<PX&&PX<450&&400<PY&&PY<500) PY-=200;
    if (500<PX&&PX<600&&0<PY&&PY<100) stage=5;
   
   
    if (PY%80==0) stage=3;

  }
  if (stage==5)
  {
    playerST2.pause();
    background(0,0,0);
    playerending.setGain(-20);
    playerending.play();
    textSize(35);
    text("Matchstick Men Finally ",100,100);
    text("arrival His Friends Side!",100,150);
    text("You Made It!",100,200);
    text("Thanks For Your Playing!",100,400);
    text("   This Game Done by↓",100,500);
    text("&",310,580);
    image(copyright,250,550,39,33);
    image(copyright2,350,550,39,33);
  }
  if (stage == 4)
  {
    playerST1.pause();
    playerST2.pause();
    image(stageBG4,0,0,600,800);
    fill(0,255,0);
    textSize(32);
    text("Game Over", 200, 350);
    playerDead.play();

  }
  if (stage ==3)
  {
    background(255);
    fill(0,0,255);
    textSize(32);
    text("Life",100,800);
    fill(255,0,0);
    rect(100,700,blood,50);
    playerST2.pause();
   
    playerST1.setGain(-20);
    playerST1.play();
    textSize(12);
    text("Use",545,760);
    text("← → ",545,780);
    text("to Move",545,800);
    textSize(25);
    text("coin : "+score,400,760);
   
   
    for ( int i = 0 ; i < N ; i++)
    {
      if (thingType[i] == 1 )
      {
         drawcoin(i) ;
         if ( dist(thingX[i],thingY[i],HeadX,HeadY)<50)
        {
          score++;
          if (blood<100) blood+=5;
          thingY[i] =620;
        }
      }
      else if (thingType[i] == 2 )
     {
       drawcone(i) ;
        if ( dist(thingX[i],thingY[i],HeadX,HeadY)<50)
        {
          blood-=10;
          thingY[i] =620;
        }
     }
      else if (thingType[i] == 3 )
      {
        drawfire(i) ;
         if ( dist(thingX[i],thingY[i],HeadX,HeadY)<50)
         {
          blood-=20;
          thingY[i] =620;
         }
      }
      thingY[i] += 4 ;
      if (score>2) thingY[i] += 5 ;
      if (score>6) thingY[i] += 7 ;
      if (thingY[i] > 600 ) newThing(i) ;  
     
    }
    people(loc) ;
    if (blood <1) stage = 4;
    if (score ==10) 
    {
      PY-=1;
      stage = 2;
    }
  }
}

void people (float x) {
    noFill();
    ellipse (225+x, 600, 30, 30) ;
    line ( 225+x, 615, 225+x, 660 );
    line ( 225+x, 625, 205+x, 640) ;
    line ( 225+x, 625, 245+x, 640) ;
    line ( 225+x, 660, 205+x, 680) ;
    line ( 225+x, 660, 245+x, 680) ;
}
void keyPressed()
{
  if (stage==1)
  {
    if (key=='s' || key =='S') stage=2;
  }
  else if (stage==2)
  {
    if(shoes==1)
    {
      if (keyCode==UP) PY-=3;
      if (keyCode==LEFT) PX-=3;
      if (keyCode==RIGHT)PX+=3;
      if (keyCode==DOWN) PY+=3;
    }
    else
    {
      if (keyCode==UP) PY-=1;
      if (keyCode==LEFT) PX-=1;
      if (keyCode==RIGHT)PX+=1;
      if (keyCode==DOWN) PY+=1;
    }
   
  }
  else if (stage==3)
  {
    if (key=='s' || key =='S') stage=2;
    if ( keyCode ==RIGHT)
    {
      loc += 200;
      if (loc >200) loc = 200;
      HeadX = loc+225;
    }
    if ( keyCode ==LEFT)
    {  
      loc -= 200;
      if (loc < -200 ) loc = -200;
      HeadX = loc+225;
    }
  }
}

void newThing(int i )

  thingY[i] = -random(300) ;
  thingX[i] = int(random(10)) * 200  ;
  thingType[i] = int (random(3)+1) ;
}

void drawcoin(int i)
{
  image(coin , thingX[i],thingY[i], 60,60) ;
}

void drawcone(int i)
{
  image(cone , thingX[i] , thingY[i] , 60 , 60) ;
}

void drawfire (int i )
{
  image(fire , thingX[i] , thingY[i] , 60 , 60) ;
}


void stop()
{
  playerDead.close();
  playerST1.close();
  playerending.close();
  minim.stop();
  super.stop();
}


沒有留言:

張貼留言