✨Week14✨
添加音樂
import ddf.minim.*;
Minim minim;
AudioPlayer player;
PImage img,img1,img2,img3,img4,img5;
float [] hole;
int N=25;
float x=100,y=100,bgx=-300,vy=2;
int time;
int a=0;
boolean alive=true;
void setup()
{
size(700,500);
img =loadImage("77.png");//BG
img1=loadImage("55.png");//sheep
img2=loadImage("88.jpg");//WinBG
img3=loadImage("66.jpg");//LoseBG
img4=loadImage("99.png");
img5=loadImage("44.png");
hole=new float[N];
for(int i=0;i<N;i++)
{
hole[i]=random(100,300);
}
minim = new Minim(this);
player = minim.loadFile("Audio.mp3");
player.play();
}
void draw()
{
image(img,-50,-200,width/0.7,height/0.7);
bgx++;
//rect(x+10,y+10,50,50);
strokeWeight(0.6);
fill(#BC885D);
for(int i=0;i<N;i++)
{
rect(i*180-bgx+300, 0,50,hole[i]);
rect(i*180-bgx+300,hole[i]+150,50, 1000);
if(x>=i*180-bgx+225 && x<=i*180-bgx+315 && y<=hole[i]-25 )alive=false;
if(x>=i*180-bgx+225 && x<=i*180-bgx+315 && y>=hole[i]+60 )alive=false;
}
textSize(50);
fill(255);
text("MouseClick!!",220,70);
time=10-(frameCount/60);
text("Time:"+time, 265,460);
image(img1.get(5, 256*a, 256,250), x,y,width/6.5,height/4.5);
if(frameCount%30==0) a = (a+1)%2;
if(y<=-45 || y>=430)alive=false;
if(alive==false)
{
image(img3,0,0,width,height);
textSize(80);
fill(#AF1010);
text("You're DEAD!!!!",62,260);
}
if(time<0)
{
image(img2,0,0,width,height);
textSize(50);
fill(#F0F2F7);
text("You're the best Clicker!!",65,270);
image(img5,x-40,y+24,width/7,height/7);
image(img1.get(5, 256*a, 256,250), x,y,width/6.5,height/4.5);
image(img4,x+33,y+20,width/10,height/8.5);
if(frameCount%60==0) a = (a+1)%2;
if(y<=-25)y=-25;
if(y>=410)y=410;
}
y=y+vy;
if (mousePressed)vy=-2;
else vy=2;
}
最後程式
import ddf.minim.*;//匯入音樂函式庫
Minim minim;
AudioPlayer player;
PImage img,img1,img2,img3,img4,img5,img6;//背景與主角
PImage []letter=new PImage[28];//文字的圖
float [] hole;//陣列放柱子的開口
int N=25;//柱子的數量
float x=100,y=100,bgx=-300,vy=2;//柱子的起始位置 羊的位置與速度
int time,sec,temp,count;//負責計時
int pic=0;//切換羊的動作
boolean alive=true,start=false;//切換場景
void setup()
{
size(700,500);//遊戲場景大小
img =loadImage("77.png");//遊戲背景
img1=loadImage("55.png");//羊
img2=loadImage("88.jpg");//獲勝背景
img3=loadImage("66.jpg");//失敗背景
img4=loadImage("99.png");//羊的頭盔
img5=loadImage("44.png");//羊的彩虹
img6=loadImage("111.jpg");//開始的背景
hole=new float[N];//柱子的開口位置隨機
for(int i=0;i<N;i++)
{
hole[i]=random(100,300);
}
minim = new Minim(this);//背景音樂
player = minim.loadFile("Audio.mp3");
player.play();
for(int i=0;i<28;i++)letter[i]=loadImage(i+".png");//匯入字母
}
void draw()
{
image(img6,0,0,width,height);//開始的背景
sec=frameCount/60;//計算幾秒的時候開始
image(letter[12], 100,205,width/13,height/11);//開始的文字
image(letter[18], 137,205,width/15,height/11);
image(letter[16], 167,205,width/14,height/11);
image(letter[12], 200,205,width/13,height/11);
image(letter[17], 240,205,width/13,height/11);
image(letter[23], 305,205,width/13,height/11);
image(letter[20], 340,205,width/15,height/11);
image(letter[22], 400,205,width/13,height/11);
image(letter[23], 440,205,width/15,height/11);
image(letter[10], 473,205,width/14,height/11);
image(letter[21], 513,205,width/13,height/11);
image(letter[23], 548,205,width/13,height/11);//Click to start
if(mousePressed)//點一下滑鼠開始
{
start=true;
count+=1;//紀錄點幾下滑鼠
}
if(count==1)temp=sec;//紀錄開始是幾秒
if(start==true)//正式開始遊戲
{
image(img,-50,-200,width/0.7,height/0.7);//背景圖
bgx++;//讓柱子移動
strokeWeight(0.6);//畫柱子
fill(#BC885D);
for(int i=0;i<N;i++)
{
rect(i*180-bgx+100, 0,50,hole[i]);//上柱子
rect(i*180-bgx+100,hole[i]+150,50, 1000);//下柱子
if(x>=i*180-bgx+25 && x<=i*180-bgx+115 && y<=hole[i]-25 )alive=false;//上柱子碰撞偵測
if(x>=i*180-bgx+25 && x<=i*180-bgx+115 && y>=hole[i]+60 )alive=false;//下柱子碰撞偵測
}
image(letter[19], 130,30,width/14,height/11);
image(letter[20], 170,30,width/13,height/11);
image(letter[24], 210,30,width/13,height/11);
image(letter[22], 250,29,width/13,height/11);
image(letter[14], 290,30,width/14,height/11);
image(letter[12], 360,30,width/13,height/11);
image(letter[18], 400,30,width/15,height/11);
image(letter[16], 430,30,width/14,height/11);
image(letter[12], 465,30,width/13,height/11);
image(letter[17], 505,30,width/13,height/11);
image(letter[26], 550,30,width/13,height/11);
image(letter[26], 565,30,width/13,height/11);//Mouse Click
image(letter[23], 190,410,width/15,height/13);
image(letter[16], 230,410,width/15,height/13);
image(letter[19], 270,410,width/15,height/13);
image(letter[14], 315,413,width/15,height/13);
image(letter[27], 360,416,width/15,height/13);
image(letter[27], 360,428,width/15,height/13);//Time:
time=10-(frameCount/60)+temp;//遊戲倒計時
int remain = time;//倒計時的時間轉圖片
int xx=435;
while(remain>0)
{
int n = remain%10;
remain = remain / 10;
image( letter[n], xx,407,50,50);
xx-=40;
}
image(img1.get(5, 256*pic, 256,250), x,y,width/6.5,height/4.5);
if(frameCount%10==0) pic = (pic+1)%2;//切換羊的動作
if(y<=-45 || y>=430)alive=false;//碰到畫面外框死掉
if(time<=0)alive=true;//撐到時間結束就還活著
if(alive==false )//死掉的畫面
{
image(img3,0,0,width,height);//死掉的背景
image(letter[25], 125,205,width/14,height/11);
image(letter[20], 165,205,width/13,height/11);
image(letter[24], 205,205,width/13,height/11);
image(letter[27], 235,204,width/13,height/11);
image(letter[21], 265,205,width/14,height/11);
image(letter[14], 300,207,width/13,height/11);
image(letter[13], 390,205,width/15,height/11);
image(letter[14], 425,205,width/14,height/11);
image(letter[10], 460,205,width/13,height/11);
image(letter[13], 500,205,width/13,height/11);
image(letter[26], 530,205,width/14,height/11);
image(letter[26], 550,205,width/13,height/11);
image(letter[26], 570,205,width/13,height/11);//You're dead
}
if(time<=0 && alive==true )//獲勝的畫面
{
image(img2,0,0,width,height);//獲勝的背景圖
image(letter[25], 105,175,width/14,height/11);
image(letter[20], 140,175,width/13,height/11);
image(letter[24], 175,175,width/13,height/11);
image(letter[27], 200,174,width/13,height/11);
image(letter[21], 225,175,width/14,height/11);
image(letter[14], 257,177,width/13,height/11);
image(letter[23], 312,175,width/15,height/11);
image(letter[15], 342,175,width/14,height/11);
image(letter[14], 377,177,width/13,height/11);
image(letter[11], 430,175,width/13,height/11);
image(letter[14], 470,175,width/14,height/11);
image(letter[22], 502,174,width/13,height/11);
image(letter[23], 537,175,width/13,height/11);
image(letter[12], 145,225,width/10,height/8);
image(letter[18], 195,225,width/11,height/8);
image(letter[16], 235,225,width/10,height/8);
image(letter[12], 278,224,width/10,height/8);
image(letter[17], 325,225,width/10,height/8);
image(letter[14], 375,227,width/10,height/8);
image(letter[21], 430,225,width/10,height/8);
image(letter[26], 480,225,width/10,height/8);
image(letter[26], 500,225,width/10,height/8);//you're the best clicker!!
image(img5,x-40,y+24,width/7,height/7);//彩虹
image(img1.get(5, 256*pic, 256,250), x,y,width/6.5,height/4.5);//小羊
image(img4,x+33,y+20,width/10,height/8.5);//頭盔
if(frameCount%60==0) pic = (pic+1)%2;
if(y<=-25)y=-25;//小羊不會飛太高
if(y>=410)y=410;//小羊不會飛太低
}
y=y+vy;//小羊的高度
if (mousePressed)vy=-2;//按滑鼠向上
else vy=2;//否則向下墜
}
}

沒有留言:
張貼留言