2.遊戲方法&截圖
遊戲開始後,下方會開始冒泡泡出來,要用滑鼠去點泡泡,泡泡會消失並且分數會加五分,如果沒有戳到泡泡而讓泡泡跑出視窗,分數會扣五分,為時一分鐘
一分鐘結束後,會秀出所得的分數
3.程式碼
int popox=0,popoy=0,popoy1=0,popoy2=0,popoy3=0,popoy4=0,popoy5=0;
int fishx=0,fishy=0;
int score=0;
int lasttime=60;
import ddf.minim.*;
AudioPlayer player,wate,cheers;
Minim minim;
PImage popo;
PImage finger;
PImage bobo;
PImage back;
PImage fish;
void setup()
{
size(800,600);
fish=loadImage("fish.png"); //游動的魚
bobo=loadImage("bobo.png"); //海綿寶寶
finger=loadImage("finger.png"); //手指
popo=loadImage("popo.png"); //泡泡
back=loadImage("back.jpeg"); //背景圖
minim=new Minim(this);
player=minim.loadFile("file.mp3", 2048); //背景音樂
player.play();
}
void draw()
{
image(back,0,0);
image(bobo,250,100);
popoy-=3; //泡泡移動量
image(popo,popox+300,popoy+600,100,100); //泡泡坐標,大小
if(popoy+600<0) //判斷泡泡是否跑出視窗
{
score-=5; //跑出視窗後扣五分
popoy=0; //泡泡回到原點再跑一次
}
popoy1-=2;
image(popo,popox+200,popoy1+500,100,100);
if(popoy1+500<0)
{
score-=5;
popoy1=0;
}
popoy2-=3;
image(popo,popox+100,popoy2+700,100,100);
if(popoy2+700<0)
{
score-=5;
popoy2=0;
}
popoy3-=5.5;
image(popo,popox+500,popoy3+650,100,100);
if(popoy3+650<0)
{
score-=5;
popoy3=0;
}
popoy4-=2;
image(popo,popox+400,popoy4+850,100,100);
if(popoy4+850<0)
{
score-=5;
popoy4=0;
}
popoy5-=3;
image(popo,popox+600,popoy5+950,100,100);
if(popoy5+950<0)
{
score-=5;
popoy5=0;
}
image(finger,mouseX-30,mouseY-30,60,60);
fishx++;
image(fish,fishx,fishy+200);
{
if(fishx>800) //判斷魚是否跑出視窗
{
fishx=0;
fishy=250;
}
}
world();
}
void mousePressed()
{
if (mouseX > popox+300 && mouseX< popox+400 && mouseY<popoy+700 && mouseY>popoy+600) //判斷滑鼠是否點到泡泡的範圍
{
popoy=600; //泡泡回到下面再跑一次
score+=5; //戳到泡泡加五分
wate=minim.loadFile("wate.wav", 2048); //戳到泡泡時播放音效
wate.play();
}
if (mouseX > popox+200 && mouseX< popox+300 && mouseY<popoy1+600 && mouseY>popoy1+500)
{
popoy1=500;
score+=5;
wate=minim.loadFile("wate.wav", 2048);
wate.play();
}
if (mouseX > popox+100 && mouseX< popox+200 && mouseY<popoy2+800 && mouseY>popoy2+700)
{
popoy2=700;
score+=5;
wate=minim.loadFile("wate.wav", 2048);
wate.play();
}
if (mouseX > popox+500 && mouseX< popox+600 && mouseY<popoy3+750 && mouseY>popoy3+650)
{
popoy3=600;
score+=5;
wate=minim.loadFile("wate.wav", 2048);
wate.play();
}
if (mouseX > popox+400 && mouseX< popox+500 && mouseY<popoy4+950 && mouseY>popoy4+850)
{
popoy4=600;
score+=5;
wate=minim.loadFile("wate.wav", 2048);
wate.play();
}
if (mouseX > popox+600 && mouseX< popox+700 && mouseY<popoy5+1050 && mouseY>popoy5+950)
{
popoy5=700;
score+=5;
wate=minim.loadFile("wate.wav", 2048);
wate.play();
}
}
void world()
{
textFont(createFont("Georgia", 48));
fill(255);
text("score:"+score, 50, 550); //分數
textFont(createFont("Georgia", 48));
fill(255);
text("Time:"+lasttime, 250, 550); //計時器
lasttime=60-millis()/1000;
if(lasttime==0) //當時間=0,秀出得分
{
stop();
textFont(createFont("Georgia", 80));
background(51,102,51);
fill(255,255,255);
text("Game Over",200,300);
text("Your score:"+score,180,400);
cheers=minim.loadFile("cheers.wav");
cheers.play();
}
}
沒有留言:
張貼留言