期中作業: Music Game
遊戲鏈結: 32位元遊戲檔案 64位元遊戲檔案 Processing原始檔案
遊戲影片:
遊戲大綱:
完整一首歌以及紀錄更新:
遊戲節圖說明:
遊戲開始畫面(字體會慢慢刷出來)
說明頁面(Check會漂浮)
選單(選擇游標、音樂、隱藏及難度)
被選擇的會從素描風格變成彩色圖片
第二首音樂的畫面(背景、數字及combo會有不同風格)
第一首音樂的畫面(右下角的menu點選到結果畫面及主選單)
結果畫面隨音樂不同改變背景(紀錄Good、Miss、Grade and MaxCombo)
結果畫面隨音樂不同改變背景(紀錄Good、Miss、Grade and MaxCombo)
游標置於音樂上會顯示最高分數(會記錄最高)
跟著游標跑的哆啦a夢(常被說噁心)
小丸子風格的按鍵放大圖
音樂圖片的素描風格
各種難度以及小丸子的素描風格
附註:
1.為了解決速度會影響預先設定普面的節奏,有調整游標從頂端到尾端速度的換算。
2.遊戲開頭文字是漸漸"刷"出來的。
3.為凸顯功能選擇與否,將遊戲圖式風格素描化。
4.游標產生會依照節奏,但按鍵位置每次都為隨機,增加可玩度。
5.防止有人按住按鍵作弊,有特別設計按下後只有6個frame間能夠感應,約0.2秒。
6.避免滑鼠按下後感應太多次,設置為只感應一次。
7.使用txt檔案紀錄對應節奏之按鍵產生時間,以及最高分數。
8.困難模式下,使用 + - 可以調整速度 z x 可以調整難度,m可以拍照。
9.遊戲本身有建立譜面的模式,但需要將某些程式碼註解調整,能自己設計譜面節奏。
10.不同音樂有不同的背景、combo圖片以及數字風格。
10.不同音樂有不同的背景、combo圖片以及數字風格。
11.滑鼠游標會有軌跡!!!!(多拉A夢= =)
程式碼:
import ddf.minim.*; AudioPlayer player; Minim minim; PFont font; /*Mouse point*/ PImage mu; //mouse image int[] Msitex=new int[7]; //save mouse site X int[] Msitey=new int[7]; //save mouse site Y /*Title use Varible*/ PImage title,nameArea,bomb,example,check; //Include logo name studID illu int move = -300,site=0; //save motion information int[] maskArr; //use to save alpha value to mask image float fly=0; //use to ellipse motion int runType=0; //decide what kind difficult level /*Result use*/ int good=0,bad=0,maxCombo=0; //save good num and bad num long gradeNum=0,tmpgrade; //save grade PImage result,goodImg,badImg,grade,resultImg,comboImg; //save image include good bad grade...word /*Menu Use */ PImage bg_menu,Music1,Music1plus,Music2,Music2plus; //save music pic PImage easy,nor,dif; //save difficult level img PImage easyPlus,norPlus,difPlus; //save difficult level img pencil style PImage btnP; //save another kind btn PImage hidden,hiddenP; //save word hidden PImage exitImg,exitImgP; //save word exit long r1=0,r2=0; //to load highest grade value String rk; //to scan file's string ( grade ) /* Game Use Varible*/ int SPEED = 5 ,ARR_SIZE=500 , DIFFACULT=9; //Define PImage img,lv,btn; //背景 combo,按鈕圖片 PImage[] number; //紀錄數字圖片 PImage menu; //to save menu background float[] sx,sy; //下降游標位置 int combo,a,b,c; //段數 int count,s,sp; //游標數,柱列指標 int rtime; //隨機時間 int i,k; //迴圈使用變數 color btn_q,btn_w,btn_e,btn_i,btn_o,btn_p,btn_space; //按件顏色 boolean[] ctl ; //控制判斷 X 座標 boolean btnStyle=true; //按鈕類型 int[] boardX; //判斷X邊界 String tmp,linee; //to temp file string long t; //to save system time (already colculate int DELAY = -2250; //set delay boolean hid=false; //choose hidden? int decide=0; int tempcount=0; int limitTime; /*Time Controler*/ long selectTime ; int typeSel=0; //Start script: 0 menu script: 1 game script: 2 result script: 3 //PrintWriter output; BufferedReader reader; BufferedReader rank; PrintWriter rankin; void setup() { //宣告陣列 ctl=new boolean[10]; boardX=new int[10]; sx=new float[ARR_SIZE]; sy=new float[ARR_SIZE]; number=new PImage[10]; //output = createWriter("2d.txt"); //size and loadImage size(800,600); font = loadFont("data/txt.vlw"); btn=loadImage("gameUse/btn.png"); title=loadImage("start/title.png"); nameArea=loadImage("start/name.png"); example= loadImage("start/Eg.jpg"); check=loadImage("start/check.png"); bg_menu=loadImage("menu/background_menu.jpg"); Music1=loadImage("menu/1.jpg"); Music1plus=loadImage("menu/1plus.jpg"); Music2=loadImage("menu/2.jpg"); Music2plus=loadImage("menu/2plus.jpg"); maskArr=new int[nameArea.width * nameArea.height]; mu=loadImage("start/mu.png"); easy=loadImage("gameUse/Easy.png"); nor=loadImage("gameUse/Normal.png"); dif=loadImage("gameUse/Diffacult.png"); easyPlus=loadImage("gameUse/EasyPlus.png"); norPlus=loadImage("gameUse/NormalPlus.png"); difPlus=loadImage("gameUse/DiffacultPlus.png"); menu=loadImage("gameUse/menuu.png"); btnP=loadImage("gameUse/btnP.png"); hiddenP=loadImage("menu/hiddenP.png"); hidden=loadImage("menu/hidden.png"); goodImg=loadImage("result/good.png"); badImg=loadImage("result/bad.png"); grade=loadImage("result/grade.png"); resultImg=loadImage("result/resultWord.png"); comboImg=loadImage("result/combo.png"); result=loadImage("background/2.jpg"); rank=createReader("data/rank.txt"); exitImg=loadImage("menu/exit.png"); exitImgP=loadImage("menu/exitP.png"); for(i=0;i<2;i++){ try{ rk = rank.readLine(); if(i==0) r1= int(rk); else if(i==1) r2=int(rk); } catch (IOException e) { e.printStackTrace(); rk = null; } } //Set orinage color value btn_q=color(255,128,128,150); btn_w=color(128,255,128,150); btn_e=color(128,128,255,150); btn_space=color(255,255,255,150); btn_i=color(128,128,255,150); btn_o=color(128,255,128,150); btn_p=color(255,128,128,150); //初值化 for(i=0;i<10;i++) ctl[i]=false; rtime=count=sp=s=combo=0; //Setting Board boardX[0]=5; boardX[1]=45; boardX[2]=85; boardX[3]=125; boardX[4]=165; boardX[5]=205; boardX[6]=245; //音樂 minim = new Minim(this); player = minim.loadFile("Music/Bald Bros - We Are (Radio Edit).mp3", 1024); } //顯示combo void showCombo(int num) { if(num&rt;=100){ c=num%10; num/=10; b=num%10; num/=10; a=num%10; image(number[a],240,100,60,80); image(number[b],300,100,60,80); image(number[c],360,100,60,80); image(lv,420,100,330,80); } else if(num&rt;=10){ c=num%10; num/=10; b=num%10; image(number[b],300,100,60,80); image(number[c],360,100,60,80); image(lv,420,100,330,80); } } //刪除元素 void del() { s++; count--; if(s==ARR_SIZE) s=0; } //增加元素 void push(int tx,int ty) { sx[sp]=tx; sy[sp++]=ty; count++; if(sp==ARR_SIZE) sp=0; } //產生下降游標 void btn(int type) { int tx=0,ty=0; switch(type) { case 0: tx=5;break; case 1: tx=45;break; case 2: tx=85;break; case 3: tx=125;break; case 4: tx=165;break; case 5: tx=205;break; case 6: tx=245;break; } push(tx,ty); } void keyPressed() { //output.println(millis()); switch(key){ case 'q': btn_q=color(246,100,196,200);ctl[0]=true;break; case 'w': btn_w=color(246,100,196,200);ctl[1]=true;break; case 'e': btn_e=color(246,100,196,200);ctl[2]=true;break; case 'i': btn_i=color(246,100,196,200);ctl[4]=true;break; case 'o': btn_o=color(246,100,196,200);ctl[5]=true;break; case 'p': btn_p=color(246,100,196,200);ctl[6]=true;break; case ' ': btn_space=color(246,100,196,200);ctl[3]=true;break; case '+': if(SPEED<12) SPEED++; DELAY+=250;break; case '-': if(SPEED&rt;1) SPEED--; DELAY-=250;break; case 'z': if(DIFFACULT &rt; 5) DIFFACULT--;break; case 'x': if(DIFFACULT < 20) DIFFACULT++;break; case 'c': btnStyle=!btnStyle;break; case 'm' :save("C:/save.jpg");break; //case 'b': output.flush();output.close();exit(); } if(tempcount++<6){ for(i=0;i<7;i++) if(ctl[i] && sy[s]<=560 && sy[s]&rt;510 && sx[s]==boardX[i] ){ combo++; decide = 0; gradeNum+=combo*100; maxCombo=combo&rt;maxCombo?combo:maxCombo; good++; del(); break; } } } void keyReleased() { switch(key){ case 'q': btn_q=color(255,128,128,150); ctl[0]=false; break; case 'w': btn_w=color(128,255,128,150); ctl[1]=false; break; case 'e': btn_e=color(128,128,255,150); ctl[2]=false; break; case ' ': btn_space=color(255,255,255,150); ctl[3]=false; break; case 'i': btn_i=color(128,128,255,150); ctl[4]=false; break; case 'o': btn_o=color(128,255,128,150); ctl[5]=false; break; case 'p': btn_p=color(255,128,128,150); ctl[6]=false; break; } tempcount=0; } void drawBtnArea() { //游標區域 strokeWeight(3); fill(btn_q); rect(5,0,40,540); fill(btn_p); rect(245,0,40,540); fill(btn_w); rect(45,0,40,540); fill(btn_o); rect(205,0,40,540); fill(btn_e); rect(85,0,40,540); fill(btn_i); rect(165,0,40,540); fill(btn_space); rect(125,0,40,540); fill(255,255,125); rect(5,530,280,30,18); } void draw() { /*Game*/ switch(typeSel) { /*Menu*/ case 0: background(0); //Start if(millis() < 9000){ image(title,250,move,300,260); if(move<100) move += 2 ; else{ //Show Name's nameArea.mask(maskArr); image(nameArea,160,350,500,70); if(++site < 499) for(i=site;i<35000;i+=225){ if(i&rt;=35000) break; maskArr[i]=250; } for(i=site++;i<35000;i+=230){ if(i&rt;=35000) break; maskArr[i]=250; } } } else{ //Waiting and Illustrate image(example,0,0,800,600); image(check,550+30*cos(fly),300+60*sin(fly+=0.04),200,50); if(mousePressed){ typeSel = 1 ; //Memo Select process time player.play(); } } break; case 1: /*Menu*/ image(bg_menu,0,0,800,600); good=bad=maxCombo=0; decide=2; textFont(font,40); /*Select Music*/ if(mouseX<225&&mouseX&rt;50&&mouseY<225&&mouseY&rt;50){ image(Music1,50,50,200,200); fill(255,255,0); text("Highest Grade",450,450); text(r1,450,500); } else image(Music1plus,50,50,150,150); if(mouseX<325&&mouseX&rt;150&&mouseY<445&&mouseY&rt;270){ image(Music2,150,270,200,200); fill(255,255,0); text("Highest Grade",450,450); text(r2,450,500); } else image(Music2plus,150,270,140,140); /*difficult*/ if(runType==0) image(easy,50,470,120,120); else image(easyPlus,50,470,120,120); if(runType==1) image(nor,200,460,120,120); else image(norPlus,200,460,120,120); if(runType==2) image(dif,350,460,120,120); else image(difPlus,350,460,120,120); if(mouseX<800&&mouseX&rt;600&&mouseY<600&&mouseY&rt;500) image(exitImg,600,500,200,100); else image(exitImgP,600,500,200,100); if(btnStyle==true){ fill(255,255,0); strokeWeight(10); rect(600,150,120,50,18); image(btnP,400,100,150,150); } else{ fill(200,200,200); strokeWeight(10); rect(600,150,120,50,18); image(btn,400,100,150,150); } if(hid==false) image(hiddenP,420,300,300,75); else image(hidden,420,300,300,75); if(mousePressed){ if(mouseX<800&&mouseX&rt;600&&mouseY<600&&mouseY&rt;500) exit(); else if(mouseY&rt;460&&mouseY<590){ if(mouseX<170&&mouseX&rt;50) runType=0; else if(mouseX<320&&mouseX&rt;50) runType=1; else if(mouseX<470&&mouseX&rt;50) runType=2; } else if(mouseY&rt;100&&mouseY<250){ if(mouseX&rt;400&&mouseX<550) btnStyle=false; else if(mouseX&rt;600&&mouseX<720) btnStyle=true; } else if(mouseY<375&&mouseY&rt;300){ if(tempcount++==0&&mouseX&rt;420&&mouseX<720) hid = !hid; } } else tempcount = 0; /*Music*/ if(mousePressed){ if(mouseX<225&&mouseX&rt;50&&mouseY<225&&mouseY&rt;50){ img = loadImage("background/1.jpg"); result=loadImage("menu/1.jpg"); lv= loadImage("gameUse/lv.png"); DIFFACULT=9; SPEED=5; limitTime=254000; for(i=0;i<10;i++){ tmp = i + ".png"; number[i]=loadImage("number/" + tmp); } if(runType==0){ reader = createReader("btn/positions.txt"); DELAY = -2160; } else if(runType==1){ reader = createReader("btn/1d.txt"); DELAY = -4600; } if(runType!=2) runType=0; if(runType!=2){ try{ linee = reader.readLine(); t=int(linee) + DELAY ; } catch (IOException e){ e.printStackTrace(); linee = null; } } player.pause(); player = minim.loadFile("Music/04 Happy End.mp3", 1024); player.play(); typeSel=2; selectTime=millis(); } else if(mouseX<325&&mouseX&rt;150&&mouseY<445&&mouseY&rt;270){ img = loadImage("background/2.jpg"); result=loadImage("menu/2.jpg"); DIFFACULT=7; SPEED=5; limitTime=209000; lv= loadImage("gameUse/cbo.png"); for(i=0;i<10;i++){ tmp = i + "a" + ".png"; number[i]=loadImage("number/" + tmp); } if(runType==0){ reader = createReader("btn/2.txt"); DELAY = -1650; } else if(runType==1){ reader = createReader("btn/2d.txt"); DELAY = -1950; } if(runType!=2) runType=0; if(runType!=2){ try{ linee = reader.readLine(); t=int(linee) + DELAY ; } catch (IOException e){ e.printStackTrace(); linee = null; } } player.pause(); player = minim.loadFile("Music/03 I'm OK.mp3", 1024); player.play(); typeSel=2; selectTime=millis(); } } break; case 2: rtime++; image(img,0,0,800,600); image(menu,600,450,200,130); drawBtnArea(); //產生游標 switch(runType) { case 0: /*easy and normal mode about*/ if(t<-50000){ typeSel=3; rankin=createWriter("data/rank.txt"); if(limitTime==254000){ rankin.println((gradeNum&rt;r1?gradeNum:r1)); rankin.println(r2); } else{ rankin.println(r1); rankin.println((gradeNum&rt;r2?gradeNum:r2)); } rankin.flush(); rankin.close(); rank=createReader("data/rank.txt"); for(i=0;i<2;i++){ try{ rk = rank.readLine(); if(i==0) r1= int(rk); else if(i==1) r2=int(rk); } catch (IOException e) { e.printStackTrace(); rk = null; } } } else if(millis()-selectTime&rt;t){ btn((int)random(0,6.99)); try{ linee = reader.readLine(); t=int(linee) + DELAY; } catch(IOException e) { } } break; case 2: /*difficult mode product about*/ if((rtime%DIFFACULT)==0) btn((int)random(0,6.99)); if(millis()-selectTime&rt;limitTime){ typeSel=3; rankin=createWriter("data/rank.txt"); if(limitTime==254000){ rankin.println((gradeNum&rt;r1?gradeNum:r1)); rankin.println(r2); } else{ rankin.println(r1); rankin.println((gradeNum&rt;r2?gradeNum:r2)); } rankin.flush(); rankin.close(); rank=createReader("data/rank.txt"); for(i=0;i<2;i++){ try{ rk = rank.readLine(); if(i==0) r1= int(rk); else if(i==1) r2=int(rk); } catch (IOException e) { e.printStackTrace(); rk = null; } } tmpgrade=gradeNum; gradeNum=0; while(count!=0) del(); player.pause(); player = minim.loadFile("Music/Bald Bros - We Are (Radio Edit).mp3", 1024); player.play(); selectTime=millis(); } break; } //Show Combo showCombo(combo); fill(255,0,255); text("Grade: " + gradeNum,20,590); fill(255,255,0); //游標繪製下降游標及調整Y for(i=s,k=0;k<count;i++,k++){ if(i==ARR_SIZE) i=0; if(hid == false){ if(btnStyle == true) rect(sx[i],sy[i],40,20,18); else image(btn,sx[i],sy[i],40,30); } else if(hid == true){ if(btnStyle == true){ if(sy[i]<380) rect(sx[i],sy[i],40,20,18); } else{ if(sy[i]<380) image(btn,sx[i],sy[i],40,30); } } sy[i]+=SPEED; /*to show good or bad */ if(decide==1){ fill(255,0,0); text("MISS",100,550); } else if(decide==0){ fill(0,255,0); text("GOOD",100,550); } fill(255,255,0); if(sy[i]&rt;560){ decide = 1; combo=0; bad++; del(); } } /*menu click*/ if(mousePressed&&mouseX&rt;600&&mouseY&rt;450){ while(count != 0) del(); selectTime=millis(); combo=0; tmpgrade=gradeNum; gradeNum=0; typeSel=3; rankin=createWriter("data/rank.txt"); if(limitTime==254000){ rankin.println((gradeNum&rt;r1?gradeNum:r1)); rankin.println(r2); } else{ rankin.println(r1); rankin.println((gradeNum&rt;r2?gradeNum:r2)); } rankin.flush(); rankin.close(); rank=createReader("data/rank.txt"); for(i=0;i<2;i++){ try{ rk = rank.readLine(); if(i==0) r1= int(rk); else if(i==1) r2=int(rk); } catch (IOException e) { e.printStackTrace(); rk = null; } } player.pause(); player = minim.loadFile("Music/Bald Bros - We Are (Radio Edit).mp3", 1024); player.play(); } break; /*Result area*/ case 3: textFont(font, 70); if(millis()-selectTime&rt;5000) typeSel=1; background(255,255,0); image(result,171,0,458,650); image(goodImg,200,100,100,100); image(badImg,200,250,100,100); image(grade,150,330,200,150); image(resultImg,300,10,200,100); image(comboImg,150,480,200,100); fill(255,0,255); text(good, 350, 180); text(bad, 350, 310); text(tmpgrade, 340, 420); text(maxCombo, 380, 550); break; } for(i=0;i<7;i++) image(mu,Msitex[i]-15,Msitey[i]-10,30,20); for(i=6;i&rt;0;i--){ Msitex[i]=Msitex[i-1]; Msitey[i]=Msitey[i-1]; } Msitex[0]=mouseX; Msitey[0]=mouseY; delay(5); }
程式碼(以防上面格式跑掉、錯誤的一般格式):
import ddf.minim.*;
AudioPlayer player;
Minim minim;
PFont font;
/*Mouse point*/
PImage mu; //mouse image
int[] Msitex=new int[7]; //save mouse site X
int[] Msitey=new int[7]; //save mouse site Y
/*Title use Varible*/
PImage title,nameArea,bomb,example,check; //Include logo name studID illu
int move = -300,site=0; //save motion information
int[] maskArr; //use to save alpha value to mask image
float fly=0; //use to ellipse motion
int runType=0; //decide what kind difficult level
/*Result use*/
int good=0,bad=0,maxCombo=0; //save good num and bad num
long gradeNum=0,tmpgrade; //save grade
PImage result,goodImg,badImg,grade,resultImg,comboImg; //save image include good bad grade...word
/*Menu Use */
PImage bg_menu,Music1,Music1plus,Music2,Music2plus; //save music pic
PImage easy,nor,dif; //save difficult level img
PImage easyPlus,norPlus,difPlus; //save difficult level img pencil style
PImage btnP; //save another kind btn
PImage hidden,hiddenP; //save word hidden
PImage exitImg,exitImgP; //save word exit
long r1=0,r2=0; //to load highest grade value
String rk; //to scan file's string ( grade )
/* Game Use Varible*/
int SPEED = 5 ,ARR_SIZE=500 , DIFFACULT=9; //Define
PImage img,lv,btn; //背景 combo,按鈕圖片
PImage[] number; //紀錄數字圖片
PImage menu; //to save menu background
float[] sx,sy; //下降游標位置
int combo,a,b,c; //段數
int count,s,sp; //游標數,柱列指標
int rtime; //隨機時間
int i,k; //迴圈使用變數
color btn_q,btn_w,btn_e,btn_i,btn_o,btn_p,btn_space; //按件顏色
boolean[] ctl ; //控制判斷 X 座標
boolean btnStyle=true; //按鈕類型
int[] boardX; //判斷X邊界
String tmp,linee; //to temp file string
long t; //to save system time (already colculate
int DELAY = -2250; //set delay
boolean hid=false; //choose hidden?
int decide=0;
int tempcount=0;
int limitTime;
/*Time Controler*/
long selectTime ;
int typeSel=0; //Start script: 0 menu script: 1 game script: 2 result script: 3
//PrintWriter output;
BufferedReader reader;
BufferedReader rank;
PrintWriter rankin;
void setup()
{
//宣告陣列
ctl=new boolean[10];
boardX=new int[10];
sx=new float[ARR_SIZE];
sy=new float[ARR_SIZE];
number=new PImage[10];
//output = createWriter("2d.txt");
//size and loadImage
size(800,600);
font = loadFont("data/txt.vlw");
btn=loadImage("gameUse/btn.png");
title=loadImage("start/title.png");
nameArea=loadImage("start/name.png");
example= loadImage("start/Eg.jpg");
check=loadImage("start/check.png");
bg_menu=loadImage("menu/background_menu.jpg");
Music1=loadImage("menu/1.jpg");
Music1plus=loadImage("menu/1plus.jpg");
Music2=loadImage("menu/2.jpg");
Music2plus=loadImage("menu/2plus.jpg");
maskArr=new int[nameArea.width * nameArea.height];
mu=loadImage("start/mu.png");
easy=loadImage("gameUse/Easy.png");
nor=loadImage("gameUse/Normal.png");
dif=loadImage("gameUse/Diffacult.png");
easyPlus=loadImage("gameUse/EasyPlus.png");
norPlus=loadImage("gameUse/NormalPlus.png");
difPlus=loadImage("gameUse/DiffacultPlus.png");
menu=loadImage("gameUse/menuu.png");
btnP=loadImage("gameUse/btnP.png");
hiddenP=loadImage("menu/hiddenP.png");
hidden=loadImage("menu/hidden.png");
goodImg=loadImage("result/good.png");
badImg=loadImage("result/bad.png");
grade=loadImage("result/grade.png");
resultImg=loadImage("result/resultWord.png");
comboImg=loadImage("result/combo.png");
result=loadImage("background/2.jpg");
rank=createReader("data/rank.txt");
exitImg=loadImage("menu/exit.png");
exitImgP=loadImage("menu/exitP.png");
for(i=0;i<2;i++){
try{
rk = rank.readLine();
if(i==0) r1= int(rk);
else if(i==1) r2=int(rk);
}
catch (IOException e) {
e.printStackTrace();
rk = null;
}
}
//Set orinage color value
btn_q=color(255,128,128,150);
btn_w=color(128,255,128,150);
btn_e=color(128,128,255,150);
btn_space=color(255,255,255,150);
btn_i=color(128,128,255,150);
btn_o=color(128,255,128,150);
btn_p=color(255,128,128,150);
//初值化
for(i=0;i<10;i++) ctl[i]=false;
rtime=count=sp=s=combo=0;
//Setting Board
boardX[0]=5;
boardX[1]=45;
boardX[2]=85;
boardX[3]=125;
boardX[4]=165;
boardX[5]=205;
boardX[6]=245;
//音樂
minim = new Minim(this);
player = minim.loadFile("Music/Bald Bros - We Are (Radio Edit).mp3", 1024);
}
//顯示combo
void showCombo(int num)
{
if(num>=100){
c=num%10;
num/=10;
b=num%10;
num/=10;
a=num%10;
image(number[a],240,100,60,80);
image(number[b],300,100,60,80);
image(number[c],360,100,60,80);
image(lv,420,100,330,80);
}
else if(num>=10){
c=num%10;
num/=10;
b=num%10;
image(number[b],300,100,60,80);
image(number[c],360,100,60,80);
image(lv,420,100,330,80);
}
}
//刪除元素
void del()
{
s++;
count--;
if(s==ARR_SIZE) s=0;
}
//增加元素
void push(int tx,int ty)
{
sx[sp]=tx;
sy[sp++]=ty;
count++;
if(sp==ARR_SIZE) sp=0;
}
//產生下降游標
void btn(int type)
{
int tx=0,ty=0;
switch(type)
{
case 0: tx=5;break;
case 1: tx=45;break;
case 2: tx=85;break;
case 3: tx=125;break;
case 4: tx=165;break;
case 5: tx=205;break;
case 6: tx=245;break;
}
push(tx,ty);
}
void keyPressed()
{
//output.println(millis());
switch(key){
case 'q': btn_q=color(246,100,196,200);ctl[0]=true;break;
case 'w': btn_w=color(246,100,196,200);ctl[1]=true;break;
case 'e': btn_e=color(246,100,196,200);ctl[2]=true;break;
case 'i': btn_i=color(246,100,196,200);ctl[4]=true;break;
case 'o': btn_o=color(246,100,196,200);ctl[5]=true;break;
case 'p': btn_p=color(246,100,196,200);ctl[6]=true;break;
case ' ': btn_space=color(246,100,196,200);ctl[3]=true;break;
case '+': if(SPEED<12) SPEED++; DELAY+=250;break;
case '-': if(SPEED>1) SPEED--; DELAY-=250;break;
case 'z': if(DIFFACULT > 5) DIFFACULT--;break;
case 'x': if(DIFFACULT < 20) DIFFACULT++;break;
case 'c': btnStyle=!btnStyle;break;
case 'm' :save("C:/save.jpg");break;
//case 'b': output.flush();output.close();exit();
}
if(tempcount++<6){
for(i=0;i<7;i++)
if(ctl[i] && sy[s]<=560 && sy[s]>510 && sx[s]==boardX[i] ){
combo++;
decide = 0;
gradeNum+=combo*100;
maxCombo=combo>maxCombo?combo:maxCombo;
good++;
del();
break;
}
}
}
void keyReleased()
{
switch(key){
case 'q': btn_q=color(255,128,128,150); ctl[0]=false; break;
case 'w': btn_w=color(128,255,128,150); ctl[1]=false; break;
case 'e': btn_e=color(128,128,255,150); ctl[2]=false; break;
case ' ': btn_space=color(255,255,255,150); ctl[3]=false; break;
case 'i': btn_i=color(128,128,255,150); ctl[4]=false; break;
case 'o': btn_o=color(128,255,128,150); ctl[5]=false; break;
case 'p': btn_p=color(255,128,128,150); ctl[6]=false; break;
}
tempcount=0;
}
void drawBtnArea()
{
//游標區域
strokeWeight(3);
fill(btn_q);
rect(5,0,40,540);
fill(btn_p);
rect(245,0,40,540);
fill(btn_w);
rect(45,0,40,540);
fill(btn_o);
rect(205,0,40,540);
fill(btn_e);
rect(85,0,40,540);
fill(btn_i);
rect(165,0,40,540);
fill(btn_space);
rect(125,0,40,540);
fill(255,255,125);
rect(5,530,280,30,18);
}
void draw()
{
/*Game*/
switch(typeSel)
{
/*Menu*/
case 0:
background(0);
//Start
if(millis() < 9000){
image(title,250,move,300,260);
if(move<100) move += 2 ;
else{
//Show Name's
nameArea.mask(maskArr);
image(nameArea,160,350,500,70);
if(++site < 499)
for(i=site;i<35000;i+=225){
if(i>=35000) break;
maskArr[i]=250;
}
for(i=site++;i<35000;i+=230){
if(i>=35000) break;
maskArr[i]=250;
}
}
}
else{
//Waiting and Illustrate
image(example,0,0,800,600);
image(check,550+30*cos(fly),300+60*sin(fly+=0.04),200,50);
if(mousePressed){
typeSel = 1 ;
//Memo Select process time
player.play();
}
}
break;
case 1:
/*Menu*/
image(bg_menu,0,0,800,600);
good=bad=maxCombo=0;
decide=2;
textFont(font,40);
/*Select Music*/
if(mouseX<225&&mouseX>50&&mouseY<225&&mouseY>50){
image(Music1,50,50,200,200);
fill(255,255,0);
text("Highest Grade",450,450);
text(r1,450,500);
}
else image(Music1plus,50,50,150,150);
if(mouseX<325&&mouseX>150&&mouseY<445&&mouseY>270){
image(Music2,150,270,200,200);
fill(255,255,0);
text("Highest Grade",450,450);
text(r2,450,500);
}
else image(Music2plus,150,270,140,140);
/*difficult*/
if(runType==0) image(easy,50,470,120,120);
else image(easyPlus,50,470,120,120);
if(runType==1) image(nor,200,460,120,120);
else image(norPlus,200,460,120,120);
if(runType==2) image(dif,350,460,120,120);
else image(difPlus,350,460,120,120);
if(mouseX<800&&mouseX>600&&mouseY<600&&mouseY>500) image(exitImg,600,500,200,100);
else image(exitImgP,600,500,200,100);
if(btnStyle==true){
fill(255,255,0);
strokeWeight(10);
rect(600,150,120,50,18);
image(btnP,400,100,150,150);
}
else{
fill(200,200,200);
strokeWeight(10);
rect(600,150,120,50,18);
image(btn,400,100,150,150);
}
if(hid==false) image(hiddenP,420,300,300,75);
else image(hidden,420,300,300,75);
if(mousePressed){
if(mouseX<800&&mouseX>600&&mouseY<600&&mouseY>500) exit();
else if(mouseY>460&&mouseY<590){
if(mouseX<170&&mouseX>50) runType=0;
else if(mouseX<320&&mouseX>50) runType=1;
else if(mouseX<470&&mouseX>50) runType=2;
}
else if(mouseY>100&&mouseY<250){
if(mouseX>400&&mouseX<550) btnStyle=false;
else if(mouseX>600&&mouseX<720) btnStyle=true;
}
else if(mouseY<375&&mouseY>300){
if(tempcount++==0&&mouseX>420&&mouseX<720) hid = !hid;
}
}
else tempcount = 0;
/*Music*/
if(mousePressed){
if(mouseX<225&&mouseX>50&&mouseY<225&&mouseY>50){
img = loadImage("background/1.jpg");
result=loadImage("menu/1.jpg");
lv= loadImage("gameUse/lv.png");
DIFFACULT=9;
SPEED=5;
limitTime=254000;
for(i=0;i<10;i++){
tmp = i + ".png";
number[i]=loadImage("number/" + tmp);
}
if(runType==0){
reader = createReader("btn/positions.txt");
DELAY = -2160;
}
else if(runType==1){
reader = createReader("btn/1d.txt");
DELAY = -4600;
}
if(runType!=2) runType=0;
if(runType!=2){
try{
linee = reader.readLine();
t=int(linee) + DELAY ;
}
catch (IOException e){
e.printStackTrace();
linee = null;
}
}
player.pause();
player = minim.loadFile("Music/04 Happy End.mp3", 1024);
player.play();
typeSel=2;
selectTime=millis();
}
else if(mouseX<325&&mouseX>150&&mouseY<445&&mouseY>270){
img = loadImage("background/2.jpg");
result=loadImage("menu/2.jpg");
DIFFACULT=7;
SPEED=5;
limitTime=209000;
lv= loadImage("gameUse/cbo.png");
for(i=0;i<10;i++){
tmp = i + "a" + ".png";
number[i]=loadImage("number/" + tmp);
}
if(runType==0){
reader = createReader("btn/2.txt");
DELAY = -1650;
}
else if(runType==1){
reader = createReader("btn/2d.txt");
DELAY = -1950;
}
if(runType!=2) runType=0;
if(runType!=2){
try{
linee = reader.readLine();
t=int(linee) + DELAY ;
}
catch (IOException e){
e.printStackTrace();
linee = null;
}
}
player.pause();
player = minim.loadFile("Music/03 I'm OK.mp3", 1024);
player.play();
typeSel=2;
selectTime=millis();
}
}
break;
case 2:
rtime++;
image(img,0,0,800,600);
image(menu,600,450,200,130);
drawBtnArea();
//產生游標
switch(runType)
{
case 0:
/*easy and normal mode about*/
if(t<-50000){
typeSel=3;
rankin=createWriter("data/rank.txt");
if(limitTime==254000){
rankin.println((gradeNum>r1?gradeNum:r1));
rankin.println(r2);
}
else{
rankin.println(r1);
rankin.println((gradeNum>r2?gradeNum:r2));
}
rankin.flush();
rankin.close();
rank=createReader("data/rank.txt");
for(i=0;i<2;i++){
try{
rk = rank.readLine();
if(i==0) r1= int(rk);
else if(i==1) r2=int(rk);
}
catch (IOException e) {
e.printStackTrace();
rk = null;
}
}
}
else if(millis()-selectTime>t){
btn((int)random(0,6.99));
try{
linee = reader.readLine();
t=int(linee) + DELAY;
}
catch(IOException e)
{
}
}
break;
case 2:
/*difficult mode product about*/
if((rtime%DIFFACULT)==0) btn((int)random(0,6.99));
if(millis()-selectTime>limitTime){
typeSel=3;
rankin=createWriter("data/rank.txt");
if(limitTime==254000){
rankin.println((gradeNum>r1?gradeNum:r1));
rankin.println(r2);
}
else{
rankin.println(r1);
rankin.println((gradeNum>r2?gradeNum:r2));
}
rankin.flush();
rankin.close();
rank=createReader("data/rank.txt");
for(i=0;i<2;i++){
try{
rk = rank.readLine();
if(i==0) r1= int(rk);
else if(i==1) r2=int(rk);
}
catch (IOException e) {
e.printStackTrace();
rk = null;
}
}
tmpgrade=gradeNum;
gradeNum=0;
while(count!=0) del();
player.pause();
player = minim.loadFile("Music/Bald Bros - We Are (Radio Edit).mp3", 1024);
player.play();
selectTime=millis();
}
break;
}
//Show Combo
showCombo(combo);
fill(255,0,255);
text("Grade: " + gradeNum,20,590);
fill(255,255,0);
//游標繪製下降游標及調整Y
for(i=s,k=0;k<count;i++,k++){
if(i==ARR_SIZE) i=0;
if(hid == false){
if(btnStyle == true) rect(sx[i],sy[i],40,20,18);
else image(btn,sx[i],sy[i],40,30);
}
else if(hid == true){
if(btnStyle == true){
if(sy[i]<380) rect(sx[i],sy[i],40,20,18);
}
else{
if(sy[i]<380) image(btn,sx[i],sy[i],40,30);
}
}
sy[i]+=SPEED;
/*to show good or bad */
if(decide==1){
fill(255,0,0);
text("MISS",100,550);
}
else if(decide==0){
fill(0,255,0);
text("GOOD",100,550);
}
fill(255,255,0);
if(sy[i]>560){
decide = 1;
combo=0;
bad++;
del();
}
}
/*menu click*/
if(mousePressed&&mouseX>600&&mouseY>450){
while(count != 0) del();
selectTime=millis();
combo=0;
tmpgrade=gradeNum;
gradeNum=0;
typeSel=3;
rankin=createWriter("data/rank.txt");
if(limitTime==254000){
rankin.println((gradeNum>r1?gradeNum:r1));
rankin.println(r2);
}
else{
rankin.println(r1);
rankin.println((gradeNum>r2?gradeNum:r2));
}
rankin.flush();
rankin.close();
rank=createReader("data/rank.txt");
for(i=0;i<2;i++){
try{
rk = rank.readLine();
if(i==0) r1= int(rk);
else if(i==1) r2=int(rk);
}
catch (IOException e) {
e.printStackTrace();
rk = null;
}
}
player.pause();
player = minim.loadFile("Music/Bald Bros - We Are (Radio Edit).mp3", 1024);
player.play();
}
break;
/*Result area*/
case 3:
textFont(font, 70);
if(millis()-selectTime>5000)
typeSel=1;
background(255,255,0);
image(result,171,0,458,650);
image(goodImg,200,100,100,100);
image(badImg,200,250,100,100);
image(grade,150,330,200,150);
image(resultImg,300,10,200,100);
image(comboImg,150,480,200,100);
fill(255,0,255);
text(good, 350, 180);
text(bad, 350, 310);
text(tmpgrade, 340, 420);
text(maxCombo, 380, 550);
break;
}
for(i=0;i<7;i++) image(mu,Msitex[i]-15,Msitey[i]-10,30,20);
for(i=6;i>0;i--){
Msitex[i]=Msitex[i-1];
Msitey[i]=Msitey[i-1];
}
Msitex[0]=mouseX;
Msitey[0]=mouseY;
delay(5);
}
沒有留言:
張貼留言