1. 遊戲畫面
遊戲開始畫面點選start布幕會拉開,且會有手槍上膛的聲音
攻擊酒瓶,打中酒瓶能得5分,時限30秒,開槍及打中都會有音效,且有背景音樂
遊戲結束將會計算所得總分。
2.DEMO影片
3.程式碼
/*Var 設定*/ import ddf.minim.*; Minim minim; AudioPlayer shoot,glass,shotgun,bgmusic,ccheer; PImage screenleft,screenright,people,bg; boolean ctl=true,ctl2=false; //control mouse press int m=1; //control ending music int siteX1=0,siteX2=350,siteX3=525; //Image site PImage gun,star; PImage [] bottle = new PImage[5];//酒瓶圖 float [] bx = new float [5];//位置 int savedTime,passedTime,gameTime; //計時器時間 int score=0;//分數 /*首頁畫面*/ void Start() { if(mousePressed&&mouseX<430&&mouseX&rt;270&&mouseY<430&&mouseY&rt;270&&ctl) ctl=false; if(ctl==false && ctl2==false){ image(screenleft, siteX1-=3, 0, width/2, height); image(screenright,siteX2+=3,0,width/2, height); image(people,siteX3+=1,150,width/4, height/1.5); if(siteX1<-350&&siteX2&rt;700&&siteX3&rt;700) ctl2=true; if(ctl2) ; } else if(ctl==true && ctl2 == false){ image(screenleft, siteX1, 0, width/2, height); image(screenright,siteX2,0,width/2, height); image(people,siteX3,150,width/4, height/1.5); fill(66,66,255); ellipse(350,350, 80,80); fill(255,255,0); textFont(createFont("Cooper Black", 20)); text("START",315,358); } } void setup() { //Size size(700,525); bg = loadImage("bg.jpg"); //Load Image screenleft = loadImage("screen_left.jpg"); screenright = loadImage("screen_right.jpg"); people = loadImage("people.png"); //Print Image image(screenleft, siteX1, 0, width/2, height); image(screenright,siteX2,0,width/2, height); image(people,siteX3,150,width/4, height/1.5); //code savedTime = millis(); //儲存遊戲開始的時間(只執行一次) gun=loadImage("gun.png"); star=loadImage("star.png"); for(int i=0;i<5;i++){ bottle[i]=loadImage("bottle.png"); } minim=new Minim(this); bgmusic=minim.loadFile("lion.wav", 2048); bgmusic.play(); } void draw() { background(bg); Start(); //code if(siteX1<-350 && siteX2&rt;700 && siteX3&rt;700){ bottle(); //酒瓶 gun(); //槍的準心 word(); //字 time(); End(); } /*結尾的拍手聲*/ if(m==1 && gameTime<0){ ccheer=minim.loadFile("ccheer.wav", 2048); ccheer.play(); m--; } } /*槍的準心設置*/ void gun(){ image(gun,530,420); image(star,mouseX-38,mouseY-35); } /*移動酒瓶的設置*/ void bottle(){ for(int i=0;i<5;i++){ image(bottle[i],i*50+bx[i],98,50,80); bx[i]+=1; if(bx[i]&rt;=700){ bx[i]=0; } } } /*畫面上的字*/ void word(){ textFont(createFont("Georgia", 40)); text("Score:",20,500); textFont(createFont("Georgia", 40));//得分數 text(score,150,500); } /*計時器*/ void time(){ //當滑鼠按下,計時器重新回到60秒 if(mousePressed&&mouseX<430&&mouseX&rt;270&&mouseY<430&&mouseY&rt;270&&ctl) ctl=false; if(ctl==false){ savedTime = millis(); if(siteX1<-350&&siteX2&rt;700&&siteX3&rt;700) ctl=true; } passedTime = millis() - savedTime; //經過的秒數 gameTime = 60-passedTime/1000; //剩下的秒數 textFont(createFont("Georgia", 40)); text("Time: "+gameTime,250, 500); } /*槍射擊 & 音效*/ void mouseClicked(){ minim=new Minim(this); shoot=minim.loadFile("BULLET.wav", 2048); shotgun=minim.loadFile("Shoutgun198.wav", 2048); glass=minim.loadFile("glass.wav",2048); //start的音效 if(siteX1<-350 && siteX2&rt;700 && siteX3&rt;700){ shoot.play(); } for(int i=0;i<5;i++){ if(mouseY&rt;100 && mouseY<175 && mouseX&rt;i*50+bx[i]+15 && mouseX<i*50+bx[i]+30){ score+=5; shoot.pause(); glass.play(); bx[i]=0; } } //槍射擊音效 if(mouseX<430&&mouseX&rt;270&&mouseY<430&&mouseY&rt;270){ if(siteX1<-350 && siteX2&rt;700 && siteX3&rt;700){ shotgun.pause(); } else shotgun.play(); } } /*結尾畫面*/ void End(){ if(gameTime<0){ background(0,0,0); fill(255,255,255); textFont(createFont("Georgia", 60)); text("Game Over ",180,200); text("Your score:"+score,150,300); fill(66,66,255); ellipse(200,400, 80,80); fill(255,255,0); textFont(createFont("Cooper Black", 30)); text("Exit",190,410); if(mousePressed && mouseX<280 && mouseX&rt;120 && mouseY<480 && mouseY&rt;320){ exit(); } } }
沒有留言:
張貼留言